Reputation: 22744
In my Nuxt.js application, I have a series of nested routes.
.
├── 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~
What I want to do is that when I launch the server (yarn run dev
), I want it to point directly into http://localhost:3000/1
instead of http://localhost:3000/
. How to achieve this?
Note that in this case, one corresponds to the path "/:choice
"
Upvotes: 2
Views: 832
Reputation: 3579
Don't know if you're still looking for an answer but, have you considered setting up a middleware file to redirect the user? I use one for auth so if user isn't logged in the middleware redirects to "/login" if "/admin" is requested. You could do the same except set up to redirect all request for "/".
To set it up just create a file in the middleware folder, let's call it redirect.js and have something like this in it:
export default function ({store, redirect, route}) {
const urlRequiresRedirect = /^\/(\/|$)/.test(route.fullPath)
if (urlRequiresRedirect) {
return redirect('/1')
}
return Promise.resolve
}
then you need that file being read so in nuxt.config.js:
router: {
middleware: ['redirect']
},
and all requests should redirect to "/1".
Upvotes: 3