Hello App!
Go to FooGo to Bar
foo
'}const Bar = {template: 'bar
'}const routes = [{path: '/foo', component: Foo}, {path: '/bar', component: Bar}]const router = new VueRouter({routes})const app = new Vue({router}).$mount('#app')
[Try it Β»](#)
Clicked navigation links will have the style class ="router-link-exact-active router-link-active" added.
* * *
## Related Attributes
Next, let's learn more about the attributes of .
### to
Represents the link to the target route. When clicked, the value of `to` is immediately passed to `router.push()`, so this value can be a string or an object describing the target location.
HomeHomeHomeHomeHomeUserRegister
### replace
If the `replace` attribute is set, clicking will call `router.replace()` instead of `router.push()`, so no history record will be left after navigation.
### append
When the `append` attribute is set, the path is appended to the current (relative) path. For example, if we navigate from `/a` to a relative path `b`, without `append` configured, the path becomes `/b`; if configured, it becomes `/a/b`.
### tag
Sometimes you want `` to render as a specific tag, like `Router Link 1 Router Link 2
Note that **class** uses active-class="_active". ### exact-active-class Configures the class to activate when the link is exactly matched. It can be overridden with the following code.Router Link 1 Router Link 2
### event Declares the event(s) used to trigger navigation. Can be a string or an array of strings. Router Link 1 The code above sets the event to `mouseover`, meaning the HTML content will change when the mouse moves over Router Link 1. ### NPM Routing Example Next, we demonstrate a simple routing example using npm. Before starting, please download the source code of this example: ( You can also download it from GitHub: [https://github.com/chrisvfritz/vue-2.0-simple-routing-example](https://github.com/chrisvfritz/vue-2.0-simple-routing-example) After downloading, unzip the directory, rename it to `vue-demo`, enter the directory, and execute the following commands: # Install dependencies, using the Taobao resource command cnpm cnpm install # Start the application, address is localhost:8080 cnpm run dev If you need to publish to a production environment, you can execute the following command: cnpm run build After successful execution, visit http://localhost:8080 to see the following interface: !(#)
YouTip