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.

Let's also add name properties to our routes for this to work.<br />

resources/assets/<strong>js</strong>/app.<strong>js</strong>: routes: [ { path: '/', component: HomePage, name:<br />

'home' }, { path: '/listing/:listing', component: ListingPage, name: 'listing' } ]<br />

We'll also have to modify our CSS now since we now have another tag wrapped<br />

around our logo. Modify the toolbar CSS rules to match those that follow.<br />

resources/assets/components/App.vue: ... #toolbar {<br />

border-bottom: 1px solid #e4e4e4; box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1); }<br />

... #toolbar a { display: flex; align-items: center; text-decoration: none; }<br />

<br />

Let's now open a listing page, such as /listing/1. If you inspect the DOM, you'll<br />

see that our toolbar now has a new a tag inside it with a correctly resolved link<br />

back to the home page:<br />

Figure 7.4. The toolbar is a link back to the home page via the RouterLink element If you click that link,<br />

you'll be taken to the home page! Remember, the page hasn't actually changed; <strong>Vue</strong> router simply swapped<br />

ListingPage for HomePage within RouterView, <strong>and</strong> also updated the browser URL via the<br />

history.pushState API:

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

Saved successfully!

Ooh no, something went wrong!