{"id":1190,"date":"2016-09-19T13:20:25","date_gmt":"2016-09-19T04:20:25","guid":{"rendered":"https:\/\/n8finch2024.local\/?p=1190"},"modified":"2019-06-30T07:01:29","modified_gmt":"2019-06-29T22:01:29","slug":"genesis-and-angular-adding-routing-to-posts-and-pages","status":"publish","type":"post","link":"https:\/\/n8finch2024.local\/genesis-and-angular-adding-routing-to-posts-and-pages\/","title":{"rendered":"Genesis and Angular: Adding Routing to Posts and Pages (Part 3)"},"content":{"rendered":"

This is the third post in a three part series on using Genesis and Angular. Part 1 can be read here<\/strong><\/a>, and Part 2 can be read here<\/strong><\/a>.\u00a0<\/em><\/p>\n

Routing is part of the magic of web applications, and not something that we really think about when we’re developing WordPress sites since it’s basically taken care of for us in using the nav menu and full on links with page reloading. But this project was all about skipping the page load, and having a view area that will dynamically load posts and pages, an “app-like state” some might say.<\/p>\n

Using Genesis and Angular to display posts and pages in an app-like state wasn’t super\u00a0straightforward. While it opened a few extra cans of worms I wasn’t expecting, adding routing for both posts and pages has proven to be\u00a0super interesting, and got me digging into WP core as well to find some answers.<\/p>\n

Let’s review the goals of this project:<\/p>\n

Primary objective:\u00a0<\/strong>Create a view area that will display all the contents of posts and pages without a page reload using\u00a0Genesis and Angular.<\/p>\n

Do this by:<\/p>\n

    \n
  1. Adding markup to my Genesis child theme<\/li>\n
  2. Fetching data with the WP REST API and Angular<\/li>\n
  3. Routing the data Angular on posts and pages<\/li>\n<\/ol>\n

    Ok, this is going to be a bit of a beast, so let’s get\u00a0truckin’…<\/p>\n

    <\/p>\n

    Move Files to Assets Folder<\/h2>\n

    The first thing we’re going to do is rearrange our file\u00a0structure a bit, so we don’t have random Angular app code and template files\u00a0all over our Genesis child theme. So, I’ve created an assets<\/code>\u00a0folder in the child theme directory, and moved the template files and also the Angular app JavaScript files out of this. If you want to look ahead, here’s the repo<\/strong><\/a> on GitHub.<\/p>\n

    If you want to follow along, the file structure (not including other Genesis files from the sample theme) is:
    \n