vue-router配置信息動態加載

一般路由配置是這樣的,用import實現懶加載

export default new Router({
    // mode: "history",
    base: "/meizu-shop/",
    routes: [
        { path: "/home", component: ()=> import('@/views/Home'), name: "home" }
    ]
})

如果routers這個數組中的內容是動態加載的,就不能用import,否則會報Cannot find module 'xxx'的錯誤,需要把動態加載的寫成require形式

routes: [
    { path: "/cart", component: resolve=> require(['@/views/Cart'], resolve), name: "cart" }
]

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章