25.06.2018 Views

Full-Stack Vue.js 2 and Laravel 5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Figure 7.13. Empty home page after navigating from listing page We currently don't have any links to the<br />

listing page from the home page, but if we did, we'd experience a similar issue.<br />

The reason is that our page components currently get their initial state from the<br />

data we've injected into the head of the document. If we navigate to a different<br />

page using <strong>Vue</strong> Router, which doesn't invoke a page refresh, the next page<br />

component will have the wrong initial state merged in.<br />

We need to improve our architecture so that when a page is navigated to we<br />

check if the model injected into the head matches the current page. To facilitate<br />

this, we'll add a path property to the model <strong>and</strong> check that it matches the active<br />

URL. If not, we'll use AJAX to get the right data from the web service:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!