我使用了Vue CLI并构建了一个spa。
在router.js
中,我尝试:
export default new Router({
mode: 'history',
routes: [
{ path: "",
name: "home",
component: Home
},
{
path: "/about",
name: "about",
component: () => {
import ("./views/About")
}
},
{
path: "/contact",
name: "contact",
component: () => {
import ("./views/Contact")
}
}
]
})
但是我的路由器链接和路由不再起作用了吗?
从这里我read是否必须安装syntax-dynamic-import
?但是,如何添加该插件webpack.config.js
?我该如何工作?
答案 0 :(得分:1)
尝试从函数返回导入:
export default new Router({
mode: 'history',
routes: [
{ path: "",
name: "home",
component: () => import("./views/Home")
},
{
path: "/about",
name: "about",
component: () => import("./views/About")
},
{
path: "/contact",
name: "contact",
component: () => import("./views/Contact")
}
]
})