I am developing a Vue app which is quite big, and I now I have to write all the routes on one page in router/index.js
and it is already becoming too long to like or even maintain. The index.js
page is full of statements like...
import This from '../components/This'
import That from '../components/That'
import ThatOther from '../components/ThatOther'
import ThatOtherOne from '../components/ThatOtherOne'
// and so on and so on...then at the bottom
var router = new Router({
routes: [
{
path: '/this',
name: 'this',
component: This
},
{
path: '/that',
name: 'that',
component: That
},
// and so on...so many lines of similar and "repetitive" code
Since my app can be grouped into "modules", is there a way to split the routes into separate files (both the import
statements and the router entries) in like router/this.js
,router/that.js...', then add them to the main route page,
router/index.js`?
In a seperate file:
in your route file import the external routes and use the spread operator: