# Dynamic Routing
+<VueSchoolLink
+ href="https://vueschool.io/lessons/vue-router-4-dynamic-routing"
+ title="Learn how to add routes at runtime"
+/>
+
Adding routes to your router is usually done via the [`routes` option](../../api/#routes) but in some situations, you might want to add or remove routes while the application is already running. Application with extensible interfaces like [Vue CLI UI](https://cli.vuejs.org/dev-guide/ui-api.html) can use this to make the application grow.
## Adding Routes
# Waiting for the result of a Navigation
+<VueSchoolLink
+ href="https://vueschool.io/lessons/vue-router-4-detecting-navigation-failures"
+ title="Learn how to detect navigation failures"
+/>
+
When using `router-link`, Vue Router calls `router.push` to trigger a navigation. While the expected behavior for most links is to navigate a user to a new page, there are a few situations where users will remain on the same page:
- Users are already on the page that they are trying to navigate to.
# Navigation Guards
+<VueSchoolLink
+ href="https://vueschool.io/lessons/route-guards"
+ title="Learn how to add navigation guards"
+/>
+
As the name suggests, the navigation guards provided by Vue router are primarily used to guard navigations either by redirecting it or canceling it. There are a number of ways to hook into the route navigation process: globally, per-route, or in-component.
## Global Before Guards
# Named Views
+<VueSchoolLink
+ href="https://vueschool.io/lessons/vue-router-4-named-views"
+ title="Learn how to use named views"
+/>
+
Sometimes you need to display multiple views at the same time instead of nesting them, e.g. creating a layout with a `sidebar` view and a `main` view. This is where named views come in handy. Instead of having one single outlet in your view, you can have multiple and give each of them a name. A `router-view` without a name will be given `default` as its name.
```html
# Programmatic Navigation
+<VueSchoolLink
+ href="https://vueschool.io/lessons/vue-router-4-programmatic-navigation"
+ title="Learn how to navigate programmatically"
+/>
+
Aside from using `<router-link>` to create anchor tags for declarative navigation, we can do this programmatically using the router's instance methods.
## Navigate to a different location
## Traverse history
+<VueSchoolLink
+ href="https://vueschool.io/lessons/go-back"
+ title="Learn how to use Vue Router to go back"
+/>
+
This method takes a single integer as parameter that indicates by how many steps to go forward or go backward in the history stack, similar to `window.history.go(n)`.
Examples
# Redirect and Alias
+<VueSchoolLink
+ href="https://vueschool.io/lessons/vue-router-4-redirect-and-alias"
+ title="Learn how to use redirect and alias"
+/>
+
## Redirect
Redirecting is also done in the `routes` configuration. To redirect from `/home` to `/`:
# Routes' Matching Syntax
+<VueSchoolLink
+ href="https://vueschool.io/lessons/vue-router-4-advanced-routes-matching-syntax"
+ title="Learn how to use advanced route routes' matching syntax"
+/>
+
Most applications will use static routes like `/about` and dynamic routes like `/users/:userId` like we just saw in [Dynamic Route Matching](./dynamic-matching.md), but Vue Router has much more to offer!
:::tip
<VueSchoolLink
href="https://vueschool.io/courses/vue-router-4-for-everyone"
title="Learn how to build powerful Single Page Applications with the Vue Router on Vue School"
-/>
+>Watch a Free Vue Router Video Course</VueSchoolLink>
Creating a Single-page Application with Vue + Vue Router feels natural: with Vue.js, we are already composing our application with components. When adding Vue Router to the mix, all we need to do is map our components to the routes and let Vue Router know where to render them. Here's a basic example:
# Introduction
+<VueSchoolLink
+ href="https://vueschool.io/courses/vue-router-4-for-everyone"
+ title="Learn how to build powerful Single Page Applications with the Vue Router on Vue School"
+>Watch a Free Vue Router Video Course</VueSchoolLink>
+
Vue Router is the official router for [Vue.js](https://vuejs.org). It deeply integrates with Vue.js core to make building Single Page Applications with Vue.js a breeze. Features include:
- Nested routes mapping