New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic routes generation for multiple component in NUXT #2256
Comments
You cannot define multiple exactly same dynamic routes, because router cannot differ them with url, such like You may wrap with different folder with them, such like pages/ Or use the same dynamic route and differ them from the route params: pages/ <template>
<div class="post">
<component :is="component"/>
</div>
</template>
<script>
export default {
beforeCreate() {
this.component = () => import(`@/components/${this.$route.params.dir}/${this.$route.params.comp}`)
}
}
</script> |
Thanks for replay @clarkdo But i want to do the exact same as given example, i know that we can define middle folders. Here we converting angular to Vue, i don't have choice to change the routes. |
In my second example,you dont need to change route. |
BTW,can you show some urls about the two routes, because I'm curious how do you determine the route such like: |
Yea, sure. For example, First Route: /:make/:model. Here Folder structure is like for the above route, we defined like the following.
Ex. Routes : http://localhost:4200/honda -- will show Make Component. But For the below routes, we need help. Second Route : /:section/:slug Based on section and slug, we defined components.
Ex routes: |
Hi @narenderv7 For this kind of dynamic routes, |
TL;DR Use extendRoutes. The question clarkdo raised was how the system should know which is which. This is usually done by advanced route matching specified with a regex. So you need to tell the router somehow what's the difference between the two routes. For you it most likely would be to tell the router what sections there are and match those before the other route. I'm sure you see that simply by a folder structure, this can't be solved without actually changing the url pattern (as clarkdo suggested). Internally nuxt uses vue-router, where this is possible with advanced matching patterns. You can create your own routes outside of the ones created automatically from the pages folder structure with extendRoutes config option. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi all,
I have routes like the following,
How to define the folder structure for these routes and generate the routes? help need please
The text was updated successfully, but these errors were encountered: