[英]Nuxt.js: how to launch the server with a specific path value?
在我的Nuxt.js应用程序中,我有一系列嵌套的路由。
.
├── index
│ ├── _choice
│ │ ├── city
│ │ │ ├── index.vue
│ │ │ ├── _zipCode
│ │ │ │ ├── index.vue
│ │ │ │ ├── street
│ │ │ │ │ ├── index.vue
│ │ │ │ │ └── _street.vue
│ │ │ │ └── street.vue
│ │ │ └── _zipCode.vue
│ │ ├── city.vue
│ │ ├── city.vue~
│ │ └── index.vue
│ ├── _choice.vue
│ └── index.vue
├── index.vue
└── index.vue~
我想做的是,当我启动服务器( yarn run dev
)时,我希望它直接指向http://localhost:3000/1
而不是http://localhost:3000/
。 如何实现呢?
请注意 ,在这种情况下,一个对应于路径“ /:choice
”
不知道您是否还在寻找答案,但是,您是否考虑过设置中间件文件来重定向用户? 我使用一个进行身份验证,因此如果用户未登录,则如果请求“ / admin”,则中间件重定向到“ / login”。 除了设置重定向所有对“ /”的请求外,您可以执行相同的操作。
要设置它,只需在中间件文件夹中创建一个文件,我们将其称为redirect.js并在其中包含以下内容:
export default function ({store, redirect, route}) {
const urlRequiresRedirect = /^\/(\/|$)/.test(route.fullPath)
if (urlRequiresRedirect) {
return redirect('/1')
}
return Promise.resolve
}
那么您需要在nuxt.config.js中读取该文件:
router: {
middleware: ['redirect']
},
并且所有请求都应重定向到“ / 1”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.