Reputation: 1646
How we can customize NUXT
routing. Currently, I am working with the default NUXT
page routing mechanism. I want to point example.vue
as the default landing page instead of index.vue
. I also need to add authentication on these routing. unfortunately, NUXT
document didn't help me well.
Upvotes: 6
Views: 10350
Reputation: 24656
To change the landing page you can use the following pages/index.vue
:
<template>
</template>
<script>
export default {
created() {
this.$router.push('/example')
},
}
</script>
when the user navigates to https://localhost:3000
the route /projects
will be pushed and the url will change to https://localhost:3000/example
, this can be seen as an internal "redirect".
Upvotes: -1
Reputation: 971
Check to middleware Property on Nuxt
You can write a middleware and call it in your index.vue as:
middleware: {
'redirect-to-example'
}
middleware/redirect-to-example.js
export default function ({ store, redirect }) {
// If the user is not authenticated
if (!store.state.authenticated) {
return redirect(301, '/example');
}
}
You find useful informations about The Context to play well with Nuxt
Upvotes: 6