Home >Web Front-end >Vue.js >The difference between router and route in vue
Router is a plugin that manages application routing, while Route is a single routing instance managed by Router, containing URL paths, components, and properties. When using it, first install vue-router, create a Router instance in main.js, define routing rules, and install it into the Vue application. Finally, use the <router-view> component to render the current route.
The difference between Router and Route in Vue.js
:
Router
Router is mainly responsible for the following functions:
push()
, replace()
and back()
Route
Route represents a specific route managed by Router, which contains the following information:
How to use?
To use Router and Route in a Vue.js application, follow these steps:
vue-router
package:npm install vue-router
main.js
or app.js
: import VueRouter from 'vue-router '
Create a new Vue Router instance and define routing rules:
<code class="javascript">const router = new VueRouter({ routes: [ { path: '/', component: Home }, { path: '/about', component: About }, ]</code>
Install the Router instance into the Vue application:
<code class="javascript">Vue.use(router);</code>
Use the <router-view>
component to render the currently active route:
<code> **总结** </code>
The above is the detailed content of The difference between router and route in vue. For more information, please follow other related articles on the PHP Chinese website!