Complete Vue.js 2 Web Development_ Practical guide to building end-to-end web development solutions with Vue.js 2

(singke) #1
Introducing Vue-Router and Loading URL-Based Components Chapter 8

It is highly advised to use the router-link element wherever possible, as it carries several


advantages over the standard link:


Mode changes: The first advantage is linked to the mode of the router. Using the
router link allows you to change the mode of your router, say from hash to
history, and not have to change every single link in your app.
CSS classes: Another advantage that comes with using the router link is a CSS
class that gets applied to links active in the "tree" and pages which are currently
being viewed. Links in the tree are parent pages which also include the root page
(for example, any links to "/" will always have the active class). This is one of the
big benefits of using the router, as adding and removing these classes manually
would require complex coding. These classes can be customized and we will do
that later.
URL parameters and named routes: The other advantage to using the router
element is the power it gives you over using named routes and passing URL
parameters. This further allows you to have one source of truth for the URL of a
page and use names and shortcuts to reference a route. More on this will be
covered later in the chapter.

Add the links to your pages within your view so you can navigate between pages. Within


the

of your website, create a new
Free download pdf