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

Commit 468ce9d

Browse files
authored
Merge pull request #2 from hisasann/feature/add-routers
Feature/add routers
2 parents 9cba4ad + 160c3dd commit 468ce9d

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
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/routed-pages/README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
# ROUTED_PAGES
22

3-
This directory contains your Application Views and Routes.
4-
The framework reads all the `*.vue` files inside this directory and creates the router of your application.
3+
nuxt.config.ts の `router.extendRoutes` でカスタムルーティングしたいが、 pages にファイルを配置すると `.vue` ファイルの名前でアクセスできてしまう。
54

6-
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/routing).
5+
それを防ぐのが、 `routed-pages``routers` です。
76

8-
router の extendRoutes でルーティングをカスタムすると `*.vue` ファイルは直接見られたくないけど、
9-
ルーティングのときには表示したいページがある。
10-
11-
それを routed-pages に置くことで、 pages のようにファイルを置くと見られるということがなくなる。
7+
routers でカスタムルーティングを定義し、 routed-pages のファイルを指定するのが pages を使わない場合のルールです。

src/routers/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ROUTERS
2+
3+
nuxt.config.ts の `router.extendRoutes` でカスタムルーティングしたいが、 pages にファイルを配置すると `.vue` ファイルの名前でアクセスできてしまう。
4+
5+
それを防ぐのが、 `routed-pages``routers` です。
6+
7+
routers でカスタムルーティングを定義し、 routed-pages のファイルを指定するのが pages を使わない場合のルールです。

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)