create route
1. Create a folder: router, build a js, import router in js, and use vue.use() to install router,
import VueRouter from 'vue-router';
Using the VueRouter plugin
Vue.use(VueRouter)
import component
import Home from '../components/Home';
import About from '../components/About';
]
2. Create a VueRouter instance and complete the route mapping configuration
Configure routing and component mapping relationship
let routes = [//Create a Vue Router instance and complete the route mapping configuration
{
path: '/home',
component: Home
},
{
path: '/about',
component: About
}
3. Import router in main.js
import router from './router'
4. Use the <router-link> tag and <router-view> tag in the App.vue component, and set the to attribute
<router-link to="/home">首页</router-link>