步骤
- 下载
yarn add vue-router
npm install vue-router
vue add router
2. 配置
import Vue from "vue"
import VueRouter from "vue-router"
import Layout from "@/views/Layout/index.vue"
import Home from "@/views/Home"
import Search from "@/views/Search"
import Play from "./../views/Play"
Vue.use(VueRouter)
const routes = [
{
path: '/',
redirect: '/layout'
},
{
path: '/layout',
component: Layout,
redirect: '/layout/home',
children: [
{
path: 'home',
component: Home
},
{
path: 'search',
component: Search
}
]
},
{
path: '/play',
component: Play
},
]
const router = new VueRouter({
routes
})
export default router
import Vue from 'vue'
import App from './App.vue'
import router from '@/router'
Vue.config.productionTip = false
new Vue({
router,
render: h => h(App),
}).$mount('#app')
- 使用
<router-view></router-view>
- 效果
|