当前位置: 首页 > Web前端 > vue.js

vue-cli多页面历史模式-问答

时间:2023-03-31 21:59:43 vue.js

简单配置importVuefrom"vue";importRouterfrom"vue-router";Vue.use(Router);constmainRoutes=[{path:'/foo',component:()=>import("../views/templates/index.vue")},];constrouter=newRouter({mode:"history",base:"/sysadmin",routes:mainRoutes,});exportdefaultrouter;main.jsimport"core-js/stable”;导入“regenerator-runtime/runtime”;从“vue”导入Vue;从“./index.vue”导入App;从“./router/index”导入路由器newVue({router,render:(h)=>h(App),}).$mount("#app");historyUncaughtSyntaxError:Unexpectedtoken'<'遇到这个问题是因为vue.config.js中的publicPath没有设置'/'可以'找不到自己配置的“sysadmin”页面。在vue.config.js中为configureWebpack添加配置configureWebpack:()=>{devServer:{historyApiFallback:{verbose:true,rewrites:[{from:/^\/index\/.*$/,to:"/index.html"},{从:/^\/sysadmin\/.*$/,到:"/sysadmin.html"},],},},}