marinaaisa/nuxt-markdown-blog-starter

Change URL Structure

rahulkumarsingh73690 opened this issue · 2 comments

How to change URL Structure For Example

http://localhost:3000/blog/bacon-ipsum/ to http://localhost:3000/bacon-ipsum/

To change the URL structure and remove the "blog" part, first open the pages directory of the project. Move the _slug.vue page from the blog folder and into the root pages directory.
Your pages folder will look like this:
pages ->
404.vue
_slug.vue
index.vue

Nuxt uses the folder structure to build out routes, so having _slug in the blog folder is why it's in the URL.

And then in the BlogCard.vue component, change the nuxt-link (removing the blog- part) so it looks like:
<nuxt-link :to="localePath({ name: 'slug', params: { slug: blog.name } })">

And that should do it.

x-N0 commented

@rahulkumarsingh73690 Did the answer solved your issue? If it does, close your issue.