Skip to content
This repository was archived by the owner on Jul 10, 2019. It is now read-only.

Commit 141d1c0

Browse files
committed
feat: add routers files and import router rule to nuxt.config.ts
1 parent 9cba4ad commit 141d1c0

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

nuxt.config.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// https://qiita.com/iwata@github/items/5bc61ea9ca1c692d0370
22
import { Configuration } from 'webpack'
33
import { Context } from '@nuxt/vue-app'
4+
import routers from './src/routers/'
45

56
const pkg = require('./package')
67

@@ -121,18 +122,11 @@ module.exports = {
121122
middleware: 'check-auth',
122123

123124
extendRoutes(routes: any, resolve: any) {
124-
// https://ja.nuxtjs.org/api/configuration-router/#extendroutes
125-
routes.push({
126-
name: 'custom-path',
127-
path: '/example/(c|d)-:a/(e|f)-:b/*',
128-
component: resolve(__dirname, 'src/routed-pages/custom-path.vue')
129-
})
130-
131-
routes.push({
132-
name: 'include',
133-
path: '/include',
134-
component: resolve(__dirname, 'src/include/include.vue')
135-
})
125+
if (routers && routers.length > 0) {
126+
for (let i = 0, len = routers.length; i < len; i++) {
127+
routers[i](routes, resolve)
128+
}
129+
}
136130
}
137131
},
138132
styleResources: {

src/routers/custom-path.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function(routes: any, resolve: any): void {
2+
// https://ja.nuxtjs.org/api/configuration-router/#extendroutes
3+
routes.push({
4+
name: 'custom-path',
5+
path: '/example/(c|d)-:a/(e|f)-:b/*',
6+
component: resolve(__dirname, '../../src/routed-pages/custom-path.vue')
7+
})
8+
}

src/routers/include.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function(routes: any, resolve: any): void {
2+
routes.push({
3+
name: 'include',
4+
path: '/include',
5+
component: resolve(__dirname, '../../src/include/include.vue')
6+
})
7+
}

src/routers/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import customPath from './custom-path'
2+
import include from './include'
3+
4+
export default [customPath, include]

0 commit comments

Comments
 (0)