You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ja/guide/essentials/dynamic-matching.md
+29Lines changed: 29 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,35 @@ const User = {
65
65
}
66
66
```
67
67
68
+
## Catch all / 404 Not found Route
69
+
70
+
Regular params will only match characters in between url fragments, separated by `/`. If we want to match **anything**, we can use the asterisk (`*`):
71
+
72
+
```js
73
+
{
74
+
// will match everything
75
+
path:'*'
76
+
}
77
+
{
78
+
// will match anything starting with `/user-`
79
+
path:'/user-*'
80
+
}
81
+
```
82
+
83
+
When using _asterisk_ routes, make sure to correctly order your routes so that _asterisk_ ones are at the end.
84
+
The route `{ path; '*' }` is usually used to 404 client side. If you are using _History mode_, make sure to [correctly configure your server](./history-mode.md) as well.
85
+
86
+
When using an _asterisk_, a param named `pathMatch` is automatically added to `$route.params`. It contains the rest of the url matched by the _asterisk_:
87
+
88
+
```js
89
+
// Given a route { path: '/user-*' }
90
+
this.$router.push('/user-admin')
91
+
this.$route.params.pathMatch// 'admin'
92
+
// Given a route { path: '*' }
93
+
this.$router.push('/non-existing')
94
+
this.$route.params.pathMatch// '/non-existing'
95
+
```
96
+
68
97
## 高度なマッチングパターン
69
98
70
99
`vue-router` はパスのマッチングエンジンとして [path-to-regexp](https://github.com/pillarjs/path-to-regexp) を使っています。これは Optional による動的なセグメント、Zero or more / One or more に対する要求、また、カスタム正規表現パターンまでもサポートしています。 これらの高度なパターンについてはこちらの [ドキュメンテーション](https://github.com/pillarjs/path-to-regexp#parameters) または、 `vue-router` の中でそれらを使っている [こちらの例](https://github.com/vuejs/vue-router/blob/dev/examples/route-matching/app.js) をご参照ください。
0 commit comments