<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by M. Wallace on Medium]]></title>
        <description><![CDATA[Stories by M. Wallace on Medium]]></description>
        <link>https://medium.com/@fadingdust?source=rss-33f1471105ca------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Gm2toRGNaHZkwy7SLnuyPg.jpeg</url>
            <title>Stories by M. Wallace on Medium</title>
            <link>https://medium.com/@fadingdust?source=rss-33f1471105ca------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 15:10:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fadingdust/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Herd those API calls! Transitioning to VueX]]></title>
            <link>https://medium.com/@fadingdust/herd-those-api-calls-transitioning-to-vuex-53525a0249d4?source=rss-33f1471105ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/53525a0249d4</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[M. Wallace]]></dc:creator>
            <pubDate>Fri, 13 Apr 2018 14:39:51 GMT</pubDate>
            <atom:updated>2018-04-13T14:39:51.685Z</atom:updated>
            <content:encoded><![CDATA[<p>Or, “How not to build a web app”</p><blockquote>“<a href="https://twitter.com/dan_abramov/status/704304462739939328?lang=en">You’ll know when you need them</a>.”</blockquote><p>A friend recently got glasses, and she was surprised. She <em>didn’t</em> know she needed them, but afterwards felt like the world was in HD.</p><p>I’ve lived a lot of my coding life like her. I didn’t know what I didn’t know.</p><p>With this <a href="https://github.com/fadingdust/wp-rest-theme/tree/wp-router">Wordpress+Vue theme</a> I’m building out, I’m taking the time that I often don’t afford myself with client/work/on-deadline projects.</p><p>Reinventing the wheel isn’t fun, and neither is refactoring 3 times in 2 weeks after an <a href="https://medium.com/@okaleniuk/premature-optimization-is-the-root-of-all-evil-is-the-root-of-evil-a8ab8056c6b">early-optimization</a>. Good thing too.</p><h3>That “Single Source of Truth” tho..</h3><p>Turns out the single-data-source idea is moving target. There are 3 common ways to handle a web-app’s internal data:</p><ol><li>On-load (no AJAX),</li><li>Direct-from-API (AJAX),</li><li>API-via-Local Store (Cached &amp; Managed).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*JbcsPmqKP1QJIO6lg9ZsFw.png" /><figcaption>Cheatsheet</figcaption></figure><p>I knew I wasn’t “doing it right” when I <a href="https://github.com/fadingdust/wp-rest-theme/tree/b28f580167987cea3e2dfdb0b624f06738dae399">released</a> code with the “<strong>Parallel, Self-Contained</strong>” model. But the <em>data was staying on-page</em>, and it wasn’t really hurting anything except load-times.</p><p>For a brief moment, I started to bootstrap some data on-load in the PHP-based index.php file. That was the really, really bad “<strong>Dual-Ended</strong>” approach which would destroy my sanity.</p><p>I realized that js variable was the basis for my “Single Source of Truth” and my API calls needed to dump <em>into</em> the initial on-load data variable at a bare minimum, <em>a la</em> the “<strong>Parallel, Centralized</strong>” approach.</p><p>But I also had moved all API-service calls together, and had thereby moved onto the “<strong>Service-Oriented</strong>” model.</p><p>That left me either making my own store-on-a-variable home-brew method, or to jump on the VueX train and learn about client-side data-stores.</p><p>Coding well includes knowing when you need to stop and look ahead.</p><h3>What’s in a Store?</h3><p><a href="https://medium.com/u/9f957486d7e5">Eder Negrete</a> Recently answered this question in a very succinct, but accurate way:</p><blockquote>The data of the current view</blockquote><blockquote>The state of the current view</blockquote><blockquote>The “is” concept. (is loading?, is ready?, is current?, etc)</blockquote><blockquote>Shared data</blockquote><p>We’ll be rolling forth on the “shared data” for the most part.</p><h3>Code Dive-In:</h3><p>This is our baseline from <a href="https://github.com/fadingdust/wp-rest-theme/tree/wp-router">the previous version</a>. Each component is talking to the API, albeit through a helper class.</p><pre>// <strong>Direct-from-API Pattern</strong></pre><pre>let wordpressService = {</pre><pre><strong>  getFromAPI</strong>: function( path, resolve, reject ){</pre><pre>    Vue.http.get( path ).then(response =&gt; {<br>        let responseData = {posts: response.data, totalPages: 1};   <br>        resolve( responseData );</pre><pre>    }).catch(error =&gt; reject(error));<br>  },</pre><pre><strong>  getPageBySlug</strong>: function(page_slug) { <br>    let path = &quot;/wp-json/wp/v2/page/?slug=&quot;+page_slug;</pre><pre>    return new Promise((resolve, reject) =&gt; {<br>        this.getFromAPI( path, resolve, reject );<br>    })<br>  }</pre><pre>};</pre><pre>// <strong>Component: =&gt; Service =&gt; API</strong><br>import WordpressService from &#39;../services/wordpress&#39;;</pre><pre>export default {<br>  props: [&#39;post_slug&#39;],<br>  created: function(){<br>    this.getPage();<br>  },</pre><pre>  methods: {<br>    <strong>getPageBySlug</strong>: function() {<br>      const wpPromisedResult = WordpressService.getPageBySlug( this.post_slug );</pre><pre>      wpPromisedResult.then(result =&gt; {<br>        if( result.posts.length &gt; 0){<br>          this.page = result.posts[0];<br>        }</pre><pre>      }).catch(err =&gt; {<br>        this.error = true;<br>      });<br>    }// getPage<br>  }</pre><pre>}</pre><p>When there is just the data-source and the presentation, it’s easy to understand: a component data becomes visible when the data shows up.</p><p>When there’s a Service &amp; Store involved, it’s now a 3-body system (ask a Mechanical Engineer). Things are getting wonky.</p><h3>How it actually happens</h3><p>Here’s the high-level summary of the Component-Store-Service relationship:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*AI7XcDm1PIY1Qbd3ZCn2Ug.png" /></figure><p>Redefining the API/Service direction &amp; having 2 functions with the same name looks redundant. I don’t recommend it, but I did it this way to show the parallels. A better approach may be to load a larger volume of data from the API, and use the store for specifics.</p><p>Most of my code for the Store is based off of <a href="https://medium.com/u/c88d3f5e8903">Ogundipe Samuel</a>’s <a href="https://github.com/samuelayo/getting_started_with_vuex/blob/master/src/store.js">very clear code</a> from <a href="https://blog.pusher.com/getting-started-vuex-state-management-vuejs/">Getting Started with VueX</a>.</p><pre>// <strong>VueX Store Pattern:</strong></pre><pre>Vue.use(Vuex);<br>const store = new Vuex.Store({<br>  <em>state</em>: {<br>    posts: [],<br>    posts_loading: false<br>  },</pre><pre><em>  mutations</em>: { // Used by store.actions <br>    <strong>STORE_POSTS</strong>: (state, { posts }) =&gt; {<br>      state.posts.push(posts);<br>    }<br>  },</pre><pre><em>  actions</em>: {  // Used by Components via dispatch()<br>    <strong>FE</strong><strong>TCH_POSTS</strong>: function ({ commit }, get_object) {<br>      const found_post = this.getters.getPost( get_object.type, get_object.slug );</pre><pre>      if( typeof found_post !== &#39;undefined&#39; ){ // In-Memory already<br>        commit(&#39;SET_POSTS_LOADING&#39;, false);</pre><pre>      }else { //no matches, hit the API<br>        commit(&#39;SET_POSTS_LOADING&#39;, true);</pre><pre>        WordpressService<br>        .getPost( get_object.type, get_object.slug )<br>        .then((response) =&gt; {<br>          if( response.posts.length == 0 ) // OPTIONAL: Handle 404s</pre><pre>          commit(&#39;STORE_POSTS&#39;, { posts: response.posts });</pre><pre>        }, err =&gt; { // seems to be rare in normal circumstances.<br>              console.log(&quot;FETCH_POST: err:&quot;, err, get_object );<br>              commit(&#39;SET_POSTS_LOADING&#39;, false);<br>        });<br>      }<br>    }</pre><pre>  },</pre><pre>  <em>getters</em>: { // Used by Component <br>    <strong>getPostBySlug</strong>: (state) =&gt; (slug) =&gt; {</pre><pre>      let foundit = state.posts.find(post =&gt; ( post.slug === slug &amp;&amp; post.type == &#39;post&#39;));</pre><pre>      if(typeof foundit == &#39;undefined&#39;) store.dispatch(&#39;FETCH_POSTS&#39;, { slug: slug } );</pre><pre>      return state.posts.find(post =&gt; post.slug === slug);<br>    }<br>  }<br>});<br>export default store</pre><p>The Component scripting becomes quite small, so long as the template has all the data it needs, which is assumed in this semi-contrived example:</p><pre>// <strong>Component &gt;&gt; Store &gt;&gt; Service &gt;&gt; API</strong></pre><pre>&lt;template&gt;<br>  &lt;div class=&quot;page-wrapper&quot;&gt;<br>    &lt;div class=&quot;article&quot; v-if=&quot;(!posts_loading &amp;&amp; this_post)&quot;&gt;<br>      &lt;h1 class=&quot;article-title&quot;&gt;{{ this_post.title.rendered }}&lt;/h1<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><pre>&lt;script&gt;<br>import Vuex from &#39;vuex&#39;;</pre><pre>export default {<br>  <em>props</em>: [&#39;post_type&#39;, &#39;post_slug&#39;],</pre><pre><em>  created</em>(){<br>    this.$store.dispatch(&#39;FETCH_POST&#39;, <br>      { type: this.post_type, slug: this.post_slug} );</pre><pre>  },</pre><pre><em>  computed</em>: {<br>    ...Vuex.mapState([&#39;posts_loading&#39;]),</pre><pre><strong>    this_post</strong>: function(){  //Get the data from Store<br>      let foundPostInStore =     this.$store.getters.getPostBySlug(this.post_slug);</pre><pre>      return foundPostInStore;<br>   }<br>}<br>&lt;/script&gt;</pre><h3>The Full Build-Out</h3><p>Pulling &amp; storing a page or post is the simplest scenario. Post Archives are much more complex: by year, by author, by term.. I simplified what I needed by using a mix of the WordPress database (everything is a post) with the basic info for each Archive header: Authors &amp; Terms:</p><ul><li>store.posts[]={id, post_type, post_meta, etc}</li><li>store.terms[] = { term_slug, taxonomy_name }</li><li>store.authors[] = {}</li></ul><p>Taxonomies (a group of terms) just filter/reduce:</p><pre>Vue.use(Vuex);<br>const store = new Vuex.Store({</pre><pre><em>getters</em>: { // Used by Component</pre><pre>getTerms: (state) =&gt; ( requested_taxonomy_name, requested_term_slug ) =&gt; {<br>    let found_term = [];<br>    if( state.terms.length &gt; 0 ){<br>      found_term = state.terms.reduce(<br>        function( accumulator, currentTerm ) {<br>          if( currentTerm.taxonomy == requested_taxonomy_name &amp;&amp; currentTerm.slug == requested_term_slug ){<br>            accumulator.push( currentTerm );<br>          }<br>          return accumulator;<br>        }, [] );<br>    }<br>    return found_term;<br>  }</pre><pre>} //getters</pre><pre>}); //store</pre><p>I used the same approach for all archives: given a requested_author_slug , return all the posts in the Store that match. I’m also certain that <a href="https://lodash.com/docs/4.17.5">lodash</a> has a better method for my pure reduce. <em>Note: UI pagination required a different approach</em>.</p><h4>The major upside?</h4><p>As the user clicks around the site, the Store acquires more and more posts. Whenever the user clicks on something already in the store (like from a post-excerpt to a post-content) it’s instantly loaded. <em>Instantly</em>. Caching API requests comes close, but now we can:</p><ol><li>Pre-fetch! The UI pagination can be 4 posts per page, but the API pagination can be 20.</li><li>Use the data across the whole session.</li></ol><h4>The major down-sides to this?</h4><ol><li>Remember, the Store is just an in-memory variable. Don’t overload it. If you need more data saved, use <a href="https://localforage.github.io/localForage/">IndexDB</a> or <a href="https://github.com/typicode/lowdb">LowDB</a>. Your users have other things running on their device.</li><li>Parallelism. I’m now writing the same function 2–3 times <em>for each data type </em>just to pass data along.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s9cMdbBxZQZviTNq9K4Gfw.png" /><figcaption>Parallelism is annoying</figcaption></figure><p>The WordPress API basically exposes each core database table. Nothing crazy. The basic routes follow the same pattern. Adding a Service to talk to the API is required, and adding a local Store is just another way to access the same thing.</p><p><strong><em>How many times you want to refactor depends on how many times you want to re-implement data-access methods.</em></strong></p><p>Choose your tradeoffs well. If the user will be blown away by 1 second load times over 0.1 second load times, then you’re good with infrastructural (CDN+Browser) caching for API requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*SifRAt1-tOdrq4BQgnj_NA.png" /><figcaption>You have 1 second. Choose Wisely.</figcaption></figure><h3>Elephant in the room (may-or-may not be bull in china shop)</h3><p>At some point, I’m unsure of why I’m recreating the WordPress API locally, other than for speed and it seems I’m not the only one:</p><blockquote>Once you have a handful of stores or branches in your state tree, you end up practically duplicating your server-side business data and relationships on the client. — <a href="https://medium.com/u/f5ad7c8e5bcf">Mark Johnson</a></blockquote><p>This is shown in its worst form with search. If the search component was hitting the API directly, WordPress itself is doing the search. Sure it’ll take an extra second and perhaps that’s fine but any store.getters.search function I would write is only searching the posts in-memory.</p><p><strong><em>Wait, I’m building my own search algorithms</em></strong><em>?</em></p><p>This all makes sense. There’s this crazy guy who <a href="https://codeburst.io/introducing-vuepress-wordpress-development-with-vue-and-graphql-f5063a97bb69">implemented his own WordPress API using GraphQL</a>. <a href="https://hackernoon.com/how-graphql-replaces-redux-3fff8289221d">I finally understand why</a>. <em>Generic REST routes can be like eating a plate of spaghetti one noodle at a time, or eating the AlphaBits cereal alphabetically.</em></p><p>Perhaps the real answer to the search problem is to just return the Post IDs?</p><h3>Summary</h3><p>There’s a debate/decision to be made about whether to use the local store as a <strong><em>caching mechanism </em></strong>or as an<strong><em> inter-component messaging system</em></strong>:</p><p><a href="https://forum.vuejs.org/t/vuex-form-best-practices/20084/4">Vuex form best practices</a></p><p>This nice how-to shows the <strong><em>inter-component messaging</em></strong> alternative to what I’m doing:</p><blockquote>a good place to start looking for application state is your component props, and more specifically, props across multiple components that share the same data</blockquote><p><a href="https://vuejsdevelopers.com/2017/08/15/vue-js-migrating-to-vuex/">Migrating A VueJS App To Vuex</a></p><h4>A few common “gotchas”:</h4><ul><li><a href="https://www.google.com/search?q=array.push+is+not+a+reactive+vuejs">array.push is not a <em>reactive</em></a> way to update the state.</li><li>Hit the store/api during created() not mounted() You might also need to hit the store on beforeRouteUpdate(to, from, next).</li><li>Each component’s default state moved out of data(); now the default state is in computed:{}.</li><li>Chaining computed variables that are Promise-based still needs the Promise. Maybe using “data_loading” variables <a href="https://github.com/bstavroulakis/vue-wordpress-pwa/blob/master/src/vuex/modules/category/actions.js">just needs to be a Promise</a>!</li></ul><h3>Next Steps</h3><p>I’ve starting using VueX as a cache-store, which isn’t what you hear most people talk about it for. Next up, I’ll try to <em>actually</em> extract the application state, perhaps on a store.current and perhaps a store.history variable.</p><p>Thanks for reading! You can compare the end-user difference the previous version:</p><p><a href="http://github.mwallace.info/">Examples from my Github Repo</a></p><p>..or checkout the code on it’s own branch:</p><p><a href="https://github.com/fadingdust/wp-rest-theme/tree/vuex-cache">fadingdust/wp-rest-theme</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53525a0249d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Review of Wordpress and Vue.Js: Router Edition]]></title>
            <link>https://medium.com/@fadingdust/review-of-wordpress-and-vue-js-router-edition-de0d0662c0b8?source=rss-33f1471105ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/de0d0662c0b8</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vue-router]]></category>
            <category><![CDATA[wordpress-web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[M. Wallace]]></dc:creator>
            <pubDate>Wed, 28 Mar 2018 16:50:37 GMT</pubDate>
            <atom:updated>2018-03-28T16:50:37.430Z</atom:updated>
            <content:encoded><![CDATA[<h3>Headless WordPress, or Head-ish WordPress?</h3><p>I tried explaining a WordPress Theme’s code to a non-nerd (yeah, the girlfriend). Analogies I tried: A blended smoothie, minestrone soup, and a zombie. Zombies won. Here goes:</p><blockquote>Wordpress has 2 parts: life &amp; death blended together. It’s a zombie, kinda slow, and not very smart, not very clean. Chaos, really.</blockquote><blockquote>Lately, all the cool kids are separating life &amp; death, as they should be. No more zombies: Just the Living (React/Angular/Vue) and Dead (Wordpress REST API data).</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cPSMxwYO8X-LkQOQRyHdiQ.png" /><figcaption>“Headless” is trending.</figcaption></figure><p>Headless WordPress is a lot of work. Tossing in the site navigation? Better recheck routing. Added a plugin? You might have to rewrite the whole thing. You basically have to recreate the <a href="https://codex.wordpress.org/Template_Tags">list of Template Tags</a> with API equivalents. Most of your time will be spent developing in Javascript what WordPress <em>already does out of the box</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5TFLFcT0qbP2qFgt5H-BVQ.png" /><figcaption><a href="https://pantheon.io/decoupled-cms">Pantheon has a great summary</a>: there are more than 2 options out there.</figcaption></figure><p>I’ll be running with Pantheon’s “Hybrid” approach. I’m still using WordPress to build each URI as it normally would. This is of course unnecessary outside of robot crawlers. My goal is to have a reasonable overlap where any URI in Vue is also able to be handled by WordPress. Consider it a paranoid approach, with WordPress as a catch-all.</p><p>Eventually, Vue will perhaps eclipse the WordPress theme, completing the full SPA approach. For now, I need the security of providing functionality of large-scale plugins like WooCommerce and Event Ticketing.</p><h3>#RouterGoals</h3><p>Wordpress has its own <a href="https://codex.wordpress.org/Rewrite_API">internal routing</a>. If you’ve been more than knee-deep in Wordpress it’s easily missed, so here are a few reminders:</p><ul><li>The .htaccess file: There is only an index.php file. Everything else is <em>virtual</em>.</li><li>Permalink Structure: Using get_the_permalink($post-&gt;ID) instead of manually typing a link.</li></ul><p>Wordpress’ Rewrite API basically covers everything in the Template Hierarchy:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*73GFbAzbRFEUqly3SvqDtQ.png" /><figcaption>The Wordpress Template Hierarchy</figcaption></figure><p><strong>Post-Types</strong>: Posts, Pages, Attachments, etc</p><p><strong>Archives</strong>: Author, Date, Taxonomy-Terms</p><p><strong>One-Offs</strong>: Search, 404, Front-Page.</p><h4>So what does VueRouter Cover?</h4><p>Initially, not much. VueRouter has a <a href="https://router.vuejs.org/en/essentials/navigation.html">&lt;router-link&gt;</a> tag equivalent to get_permalink().</p><p>But to use that tag, you’ll have to add in every URI path format yourself. Most Vue-WordPress themes get pretty stingy when it comes to URI paths. Your router implementation starts looking like this from <a href="https://medium.com/u/8f2f50bc033">Michael Soriano</a>, at best:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/687e9b9307f2fbf7e6c5ac310e07953b/href">https://medium.com/media/687e9b9307f2fbf7e6c5ac310e07953b/href</a></iframe><p>But this is using a non-standard URI prefix for posts and pages, and other implementations use too many IDs instead of slugs. These “pretty permalinks” are much more common and SEOy:</p><pre>/page-name<br>/parent-page/page-name<br>/category/category-name<br>/category-name/post-title<br>/2017/10/<br>/author/wiley-coyote/</pre><p>The <a href="https://github.com/gilbitron/wp-rest-theme/blob/master/functions.php">only automated approach I saw</a> stuck to listing out all posts and pages. Valiant effort by <a href="https://medium.com/u/d1ad01242576">Gilbert Pellegrom</a> for a simple, first-round <a href="https://deliciousbrains.com/creating-a-wordpress-theme-using-the-rest-api-and-vue-js/">kick-off 2 years ago</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2dc7bbbd0dd45b8a47ef83ead4275cf/href">https://medium.com/media/d2dc7bbbd0dd45b8a47ef83ead4275cf/href</a></iframe><p>But what about Categories? Custom Taxonomies? ..and what if I install a plugin for events or galleries? Those will use more custom taxonomies and post types. I’m not going to manually enter in each.</p><h3>Enter: A Drop-in WordPress-Vue Route Builder.</h3><p>Believe it or not, I’d actually came up with a similar approach as Mr. Pellegrom by the time I came across his code. I had already coded up over half of the WordPress Rewrites, so I’m starting <a href="https://github.com/fadingdust/wp-rest-theme/tree/vue-2">with his simple theme</a> (updated for Vue2) as a demo.</p><p><a href="https://github.com/fadingdust/wp-rest-theme/blob/wp-router/includes/vue-router.php">fadingdust/wp-rest-theme</a></p><p>The fundamental approach lies in rolling out what is known (category slugs, parent pages, etc). Otherwise, “Category” could be confused as a parent-page, and a parent-page could be a taxonomy, or term!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*yzVkLNntQ4S78fCqM0t51g.png" /><figcaption>Routes created using the <a href="https://raw.githubusercontent.com/WPTRT/theme-unit-test/master/themeunittestdata.wordpress.xml">Theme Unit Test</a>. Still fast with over 300 routes!</figcaption></figure><p>The only truly “manual” entries are the WordPress default paths for Search, Author, and Date Archives. I lifted those straight from a <a href="https://codex.wordpress.org/Plugin_API/Filter_Reference/rewrite_rules_array">WP Rewrites dump</a>.</p><h3>Benefits</h3><ol><li>The only routes you need to mod are your own custom ones.</li><li>Supports common Component Names: <em>Page, Blog, Home, Archive, Post, Search, Author, ArchiveDate</em>. What you attach to these is up to you.</li><li>Pulls in Page Template names as Component Names for the page using it.</li></ol><h4>Resolvable URIs</h4><pre><strong>Pages</strong>:<br>/about/<br>/about/page-image-alignment/</pre><pre><strong>Archive</strong>: <br>/category-three/<br>/category/category-three/<br>/post_tag/<br>/custom-taxonomy/custom-term/</pre><pre><strong>Archive by Date</strong>:<br>/2017/10/</pre><pre><strong>Single Post</strong>:<br>/uncategorized/hello-world/<br>/custom-post-type/post-name/</pre><pre><strong>Author</strong>:<br>/author/road-runner/</pre><pre><strong>Search</strong>:<br>/search/markup+formatting</pre><pre><strong>404</strong>:<br>/XYZ</pre><h3>Usage</h3><h4>High Level</h4><p>Have a WordPress Install? Know NPM? <a href="https://github.com/fadingdust/wp-rest-theme">Give a go</a>!</p><p><a href="https://github.com/fadingdust/wp-rest-theme/tree/wp-router">fadingdust/wp-rest-theme</a></p><h4>Medium Level</h4><p>If you’ve got your own WP Theme using Vue, basically, just toss in the <a href="https://github.com/fadingdust/wp-rest-theme/blob/wp-router/includes/vue-router.php">vue-router.php</a> file, and check the integrations:</p><p><strong>PHP: </strong><a href="https://github.com/fadingdust/wp-rest-theme/blob/wp-router/functions.php"><strong>functions.php</strong></a></p><pre>$wp_vue= new WP_Vue_Router_Context();</pre><pre>wp_localize_script( &#39;rest-theme-vue&#39;, &#39;wp&#39;, <br>  array(  <br>  &#39;root&#39;      =&gt; esc_url_raw( rest_url() ),  <br>  &#39;base_url&#39;  =&gt; $base_url,  <br>  &#39;components&#39;=&gt; $wp_vue-&gt;get_components(),  <br>  &#39;routes&#39;    =&gt; $wp_vue-&gt;get_routes(), <br>  ) <br>);</pre><p><strong>JS: </strong><a href="https://github.com/fadingdust/wp-rest-theme/blob/master/rest-theme/src/main.js"><strong>rest-theme/src/main.js</strong></a></p><pre>var router = new VueRouter({  mode: &#39;history&#39;});</pre><pre>for (var key in wp.routes) {    <br>  var route = wp.routes[key];    <br>  router.addRoutes([ {        <br>    path: wp.base_path + route.slug,        <br>    component: Vue.component(capitalize(route.type)),        <br>    props: {default: true, postId: route.id}    <br>  }]);<br>}</pre><h3>Closing Thoughts</h3><p>I’m not yet sure whether I just created a crutch, or laid down a first paving-stone. Either way, I plan to extend this basic theme into something I can use for client sites with lots of plugins, as well as building it out to handle caching, etc like <a href="https://medium.com/u/53c6721ade5e">Bill Stavroulakis</a> <a href="https://github.com/bstavroulakis/vue-wordpress-pwa">PWA site</a>.</p><p>If you’ve got routing problems on your present WP Theme using Vue, I’d love to hear your issues.</p><h3>Next Steps</h3><p>There are a handful of routes that are still missing. I declined to handle Post-Attachments and Comment-Paging, since they are often handled in other ways. I also will defer to WordPress for per-category RSS feed handling.</p><ul><li>Right now, I’m pulling a list of Components; I’d like to feed it a list of registered Vue Components, instead of unsetting and re-adding.</li><li>Options for which object-types, or categories.</li><li>I’ve yet to test this with various plugins.</li></ul><p>Pull Requests are now open!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de0d0662c0b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>