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.

...import axios from 'axios';<br />

export default {<br />

data() { ... }, components: { ... }, beforeRouteEnter (to, from, next) {<br />

let serverData = JSON.parse(window.vuebnb_server_data); if<br />

(to.path === serverData.path) {<br />

let listing_groups = groupByCountry(serverData.listings);<br />

next(component => component.listing_groups = listing_groups); }<br />

else {<br />

axios.get(`/api/`).then(({ data }) => {<br />

let listing_groups = groupByCountry(data.listings); next(component<br />

=> component.listing_groups = listing_groups); });<br />

}<br />

}<br />

}<br />

And with that, we can now navigate to the home page in two ways,<br />

either via the address bar, or by going from a link from the listing<br />

page. Either way, we get the right data!

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

Saved successfully!

Ooh no, something went wrong!