Skip to content
This repository was archived by the owner on Jul 10, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// https://qiita.com/iwata@github/items/5bc61ea9ca1c692d0370
import { Configuration } from 'webpack'
import { Context } from '@nuxt/vue-app'
import routers from './src/routers/'

const pkg = require('./package')

Expand Down Expand Up @@ -121,18 +122,11 @@ module.exports = {
middleware: 'check-auth',

extendRoutes(routes: any, resolve: any) {
// https://ja.nuxtjs.org/api/configuration-router/#extendroutes
routes.push({
name: 'custom-path',
path: '/example/(c|d)-:a/(e|f)-:b/*',
component: resolve(__dirname, 'src/routed-pages/custom-path.vue')
})

routes.push({
name: 'include',
path: '/include',
component: resolve(__dirname, 'src/include/include.vue')
})
if (routers && routers.length > 0) {
for (let i = 0, len = routers.length; i < len; i++) {
routers[i](routes, resolve)
}
}
}
},
styleResources: {
Expand Down
10 changes: 3 additions & 7 deletions src/routed-pages/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# ROUTED_PAGES

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

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

router の extendRoutes でルーティングをカスタムすると `*.vue` ファイルは直接見られたくないけど、
ルーティングのときには表示したいページがある。

それを routed-pages に置くことで、 pages のようにファイルを置くと見られるということがなくなる。
routers でカスタムルーティングを定義し、 routed-pages のファイルを指定するのが pages を使わない場合のルールです。
7 changes: 7 additions & 0 deletions src/routers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ROUTERS

nuxt.config.ts の `router.extendRoutes` でカスタムルーティングしたいが、 pages にファイルを配置すると `.vue` ファイルの名前でアクセスできてしまう。

それを防ぐのが、 `routed-pages` と `routers` です。

routers でカスタムルーティングを定義し、 routed-pages のファイルを指定するのが pages を使わない場合のルールです。
8 changes: 8 additions & 0 deletions src/routers/custom-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function(routes: any, resolve: any): void {
// https://ja.nuxtjs.org/api/configuration-router/#extendroutes
routes.push({
name: 'custom-path',
path: '/example/(c|d)-:a/(e|f)-:b/*',
component: resolve(__dirname, '../../src/routed-pages/custom-path.vue')
})
}
7 changes: 7 additions & 0 deletions src/routers/include.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function(routes: any, resolve: any): void {
routes.push({
name: 'include',
path: '/include',
component: resolve(__dirname, '../../src/include/include.vue')
})
}
4 changes: 4 additions & 0 deletions src/routers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import customPath from './custom-path'
import include from './include'

export default [customPath, include]