第一步,优化
import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/Login'
import Layout from '@/views/Layout'
import Home from '@/views/Layout/Home'
const Search = () => import( '@/views/Search')
const SearchResultList = () => import( '@/views/Search/ResultList')
Vue.use(VueRouter)
const routes = [
{
path: '/',
redirect: '/layout'
}, {
path: '/login',
component: Login
}, {
path: '/layout',
component: Layout,
redirect: '/layout/home',
children: [
{
path: 'home',
component: Home,
meta: {
scrollY: 0
}
}, {
path: 'user',
component: User
}
]
}, {
path: '/search',
component: Search
}, {
path: '/search/:keyword',
name: 'resultlist',
component: SearchResultList
}
]
const router = new VueRouter({
routes
})
export default router
官网
https://router.vuejs.org/zh/guide/advanced/lazy-loading.html#%E6%8A%8A%E7%BB%84%E4%BB%B6%E6%8C%89%E7%BB%84%E5%88%86%E5%9D%97
第二步检查是否成功
|