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/router-configuration.md
+16-10Lines changed: 16 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,9 @@ const router = new Router(options)
21
21
22
22
## Routes Definition
23
23
24
-
The route tree con be configured as a callback, that receives a `route` function
24
+
The route tree can be configured as a callback, that receives a `route` function
25
25
26
-
`route` first argument must be a unique name, the second (optional) argument is the route options and the third (also optional) is a caal back to configure the children.
26
+
`route` first argument must be a unique name, the second (optional) argument is the route options and the third (also optional) is a callback to configure the children.
27
27
28
28
The route options can be `path`, `abstract` or arbitrary ones that can be used by the middlewares.
29
29
@@ -80,33 +80,39 @@ const router = new Router()
80
80
router.map(routes)
81
81
```
82
82
83
-
### Nested paths
83
+
### Nested Routes
84
84
85
-
Nested paths are concatenated unless they start with a '/'. For example
85
+
Nested routes are defined by passing a callback to the `route` function or, when using the array notation, by defining a `children` property.
86
+
87
+
Each route is associated to a path composed by its own path concatenated with the parent routes paths.
86
88
87
89
```js
88
90
router.map(function (route) {
89
91
route('foo', {path:'/foo'}, function () {
90
-
route('bar', {path:'/bar'}, function () {
91
-
route('baz', {path:'/baz'})
92
+
route('bar', {path:'bar'}, function () {
93
+
route('baz', {path:'baz'})
92
94
});
93
95
})
94
96
})
95
97
```
96
98
97
-
The above map results in 1 URL `/baz` mapping to ['foo', 'bar', 'baz'] routes.
99
+
The above map results in one path `/foo/bar/baz` mapping to ['foo', 'bar', 'baz'] routes.
100
+
101
+
Nested paths are concatenated unless they start with a '/'. For example
98
102
99
103
```js
100
104
router.map(function (route) {
101
105
route('foo', {path:'/foo'}, function () {
102
-
route('bar', {path:'bar'}, function () {
103
-
route('baz', {path:'baz'})
106
+
route('bar', {path:'/bar'}, function () {
107
+
route('baz', {path:'/baz'})
104
108
});
105
109
})
106
110
})
107
111
```
108
112
109
-
The above map results in 1 URL `/foo/bar/baz` mapping to ['foo', 'bar', 'baz'] routes.
113
+
The above map results in one path `/baz` mapping to ['foo', 'bar', 'baz'] routes.
114
+
115
+
When a navigation occurs, the route with the path which best matches the current URL is matched together with its parents, e.g., when 'bar' route is matched, 'foo' will also be matched even if 'foo' path is not related at all with current URL.
0 commit comments