Automattic is building a React.js based theme called Picard. All the JS code is in picard.js
, which you can see a reference to below. Although WordPress doesn't have a "router" per se (as explained here), React.js does and it is being used in this application to change the URL when a post is displayed.
My question is, if I wanted to build a JS application to display the posts (say in a file called posts.js
), how can I use a different JS application (say in a file called post.js
) to display an individual post?
In other words, if I don't want to use a client side router, but rather just have a small JS application created (and lazy loaded) for an individual post, and then if a user clicks back to see the lists of posts, have posts.js
loaded.
function picard_scripts() {
wp_enqueue_style( 'picard-style', get_stylesheet_uri(), '20150405' );
wp_register_script( 'picard-script', get_template_directory_uri() .
'/picard.js', array(), '20150506', true );
wp_enqueue_script( 'picard-script' );
wp_enqueue_style( 'genericons', get_template_directory_uri() .
'/genericons/genericons.css', array(), '3.4' );
}
add_action( 'wp_enqueue_scripts', 'picard_scripts' );
In case you're wondering, I don't want to use a client side router because I find them buggy, but I do want to build UI's in JavaScript, so I'd prefer to just rely on WordPress to handle the URL/routing (even though WordPress doesn't have a router).