Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Nuxt.js automatic file based route generation in favor of a manually generated routes.js file?

As we may know, Nuxt.js generates its routes by default based on the file structure of the pages folder.

What I want to know is, how to use a file and put my routes by myself, manually, instead of have Nuxt.js generating them for me?

Why?

I want more control of my routes, more explicit code and less files on the project.

I think its more easy to setup route params defining them explicit into a routes.js file rather then setting them by adding files into the project.

Any idea of how to do that, like on a normal Vue App? Thanks.

like image 678
Eleandro Duzentos Avatar asked Apr 12 '19 14:04

Eleandro Duzentos


People also ask

How do I turn off nuxt link?

<nuxt-link> is essentially <router-link> of Vue Router. You can disable it using the event prop.

Can I use vue3 with nuxt?

Vue 3 and Vite SupportWith Nuxt 3 being written in Vue 3, you get access to features like the Composition API, better module imports, and overall improved app performance. Nuxt 3 also comes with Vite support, which is backwards compatible with Nuxt 2.

How does nuxt routing work?

Nuxt automatically generates the vue-router configuration for you, based on your provided Vue files inside the pages directory. That means you never have to write a router config again! Nuxt also gives you automatic code-splitting for all your routes.


1 Answers

You can use @nuxtjs/router for that https://www.npmjs.com/package/@nuxtjs/router

Another option is to enchance automatic routing with https://github.com/nuxt-community/router-extras-module

like image 153
Aldarund Avatar answered Sep 26 '22 01:09

Aldarund