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.

<strong>Vue</strong> Router<br />

Some frontend frameworks, such as Angular or Ember, include a router library<br />

out-of-the-box. The philosophy guiding these frameworks is that the developer is<br />

better served with a complete, integrated solution for their SPA.<br />

Others frameworks/libraries, such as React <strong>and</strong> <strong>Vue</strong>.<strong>js</strong>, do not include a router.<br />

Instead, you must install a separate library.<br />

In the case of <strong>Vue</strong>.<strong>js</strong>, an official router library is available called <strong>Vue</strong> Router.<br />

This library has been developed by the <strong>Vue</strong>.<strong>js</strong> core team, so it is optimized for<br />

usage with <strong>Vue</strong>.<strong>js</strong> <strong>and</strong> makes full use of fundamental <strong>Vue</strong> features such as<br />

components <strong>and</strong> reactivity.<br />

With <strong>Vue</strong> Router, different pages of the application are represented by different<br />

components. When you set up <strong>Vue</strong> Router, you will pass in configuration to tell<br />

it which URLs map to which component. Then, when a link is clicked in the app,<br />

<strong>Vue</strong> Router will swap the active component so as to match the new URL, for<br />

example:<br />

let routes = [<br />

{ path: '/', component: HomePage },<br />

{ path: '/about', component: AboutPage },<br />

{ path: '/contact', component: ContactPage }<br />

];<br />

Since rendering a component is an almost instantaneous process in normal<br />

circumstances, the transition between pages with <strong>Vue</strong> Router is as well.<br />

However, there are asynchronous hooks that can be invoked to give you the<br />

opportunity to load new data from the server, if your different pages require it.

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

Saved successfully!

Ooh no, something went wrong!