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

Commit f18919f

Browse files
committed
feat: add routing validate
1 parent 241b451 commit f18919f

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

src/pages/example/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ section
5151
nuxt-link(to='/example/now-utcoffset') now-utcoffset
5252
p
5353
nuxt-link(to='/example/vue-carousel') vue-carousel
54+
p
55+
nuxt-link(to='/example/routing-validate/true') routing-validate - validate is true
56+
p
57+
nuxt-link(to='/example/routing-validate/false') routing-validate - validate is not true
5458
</template>
5559

5660
<script lang="ts">
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<template lang="pug">
2+
section.container
3+
h1.title
4+
| routing-validate
5+
div
6+
p path: {{ path }}
7+
p params: {{ params }}
8+
p query: {{ query }}
9+
</template>
10+
11+
<script lang="ts">
12+
import { Component, Vue } from 'nuxt-property-decorator'
13+
14+
@Component
15+
export default class extends Vue {
16+
public asyncData({ route }: any) {
17+
return {
18+
path: route.path,
19+
params: route.params,
20+
query: route.query
21+
}
22+
}
23+
24+
public validate({ params, query, store }) {
25+
if (params.condition === 'true') {
26+
return true // params バリデーションを通過したとき
27+
}
28+
29+
return false // Nuxt.js がルートをレンダリングするのを中止して、エラーページを表示させる
30+
}
31+
32+
public head() {
33+
return {
34+
title: 'routing-validate'
35+
}
36+
}
37+
}
38+
</script>

src/routers/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import customPath from './custom-path'
2+
import routingValidate from './routing-validate'
23
import include from './include'
34

4-
export default [customPath, include]
5+
export default [customPath, routingValidate, include]

src/routers/routing-validate.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import INuxtRoute from '../interfaces/INuxtRoute'
2+
3+
export default function(
4+
resolve: (dirname: string, routeDir: string) => string
5+
): INuxtRoute {
6+
return {
7+
name: 'routing-validate',
8+
path: '/example/routing-validate/:condition/',
9+
component: resolve(__dirname, '../routed-pages/routing-validate.vue')
10+
}
11+
}

0 commit comments

Comments
 (0)