Vue.js nuxt router.js在vuejs应用程序中运行npm run dev后重写
我在一个项目中(已经被其他人编码),它有router.js文件,包括所有应用程序的路由,并在一个函数中创建,代码如下Vue.js nuxt router.js在vuejs应用程序中运行npm run dev后重写,vue.js,vue-router,nuxt.js,Vue.js,Vue Router,Nuxt.js,我在一个项目中(已经被其他人编码),它有router.js文件,包括所有应用程序的路由,并在一个函数中创建,代码如下 export function createRouter() { return new Router({ mode: 'history', base: decodeURI('/'), linkActiveClass: 'nuxt-link-active', linkExactActiveClass: 'nuxt-link-exact-activ
export function createRouter() {
return new Router({
mode: 'history',
base: decodeURI('/'),
linkActiveClass: 'nuxt-link-active',
linkExactActiveClass: 'nuxt-link-exact-active',
scrollBehavior,
routes: [{
path: "/login",
component: _32e99e0f,
name: "login"
}, {
path: "/orders",
component: _5838bb72,
name: "orders"
}, {
path: "/profile",
component: _1a272ccf,
name: "profile"
}, {
path: "/orders/new",
component: _2c62ddc3,
name: "orders-new"
}, {
path: "/orders/new/:step",
component: _91e13fc8,
name: "orders-new-step"
}, {
path: "/orders/:order",
component: _14e0655f,
name: "orders-order"
}, {
path: "/",
component: _6941faf8,
name: "index"
}],
fallback: false
})
}
此函数已导入并在index.js文件中名为createApp的函数中调用,代码如下
async function createApp(ssrContext) {
const router = await createRouter(ssrContext)
const store = createStore(ssrContext)
// Add this.$router into store actions/mutations
store.$router = router
.
.
.
}
它似乎存储在数组中,并且在全球使用似乎可以,
当我改变其中一条路线并创建一条新路线时,就会出现问题,如
export function createRouter() {
return new Router({
mode: 'history',
base: decodeURI('/'),
linkActiveClass: 'nuxt-link-active',
linkExactActiveClass: 'nuxt-link-exact-active',
scrollBehavior,
routes: [{
path: "/new-route",
component: _newname,
name: "newRoute"
},
.
.
.
当我使用npm run dev
或npm run generate
时,函数及其数据已被覆盖并返回到原始代码。
有人能告诉我发生了什么吗?听着,我对vue.js很陌生;)需要一些帮助。tldr:Nuxt.js会根据pages目录中vue文件的文件树自动生成vue路由器配置。天啊!谢谢@lawrencerone,在混乱的一周后你救了我。