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/api/README.md
+55-45Lines changed: 55 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ sidebar: auto
22
22
23
23
Sometimes we may want the active class to be applied to an outer element rather than the `<a>` tag itself, in that case, you can render that outer element using `<router-link>` and wrap the raw `<a>` tag inside:
24
24
25
-
```html
25
+
```html
26
26
<router-linktag="li"to="/foo">
27
27
<a>/foo</a>
28
28
</router-link>
@@ -39,7 +39,7 @@ In this case the `<a>` will be the actual link (and will get the correct `href`)
39
39
40
40
Denotes the target route of the link. When clicked, the value of the `to` prop will be passed to `router.push()` internally, so the value can be either a string or a location descriptor object.
41
41
42
-
```html
42
+
```html
43
43
<!-- literal string -->
44
44
<router-linkto="home">Home</router-link>
45
45
<!-- renders to -->
@@ -58,7 +58,9 @@ In this case the `<a>` will be the actual link (and will get the correct `href`)
@@ -79,7 +81,7 @@ In this case the `<a>` will be the actual link (and will get the correct `href`)
79
81
80
82
Setting `append` prop always appends the relative path to the current path. For example, assuming we are navigating from `/a` to a relative link `b`, without `append` we will end up at `/b`, but with `append` we will end up at `/a/b`.
@@ -90,7 +92,7 @@ In this case the `<a>` will be the actual link (and will get the correct `href`)
90
92
91
93
Sometimes we want `<router-link>` to render as another tag, e.g `<li>`. Then we can use `tag` prop to specify which tag to render to, and it will still listen to click events for navigation.
92
94
93
-
```html
95
+
```html
94
96
<router-linkto="/foo"tag="li">foo</router-link>
95
97
<!-- renders as -->
96
98
<li>foo</li>
@@ -112,9 +114,9 @@ In this case the `<a>` will be the actual link (and will get the correct `href`)
112
114
113
115
One consequence of this is that `<router-link to="/">` will be active for every route! To force the link into "exact match mode", use the `exact` prop:
114
116
115
-
```html
117
+
```html
116
118
<!-- this link will only be active at `/` -->
117
-
<router-linkto="/"exact>
119
+
<router-linkto="/"exact></router-link>
118
120
```
119
121
120
122
Check out more examples explaining active link class [live](https://jsfiddle.net/8xrk1n9f/).
@@ -141,7 +143,7 @@ Any non-name props will be passed along to the rendered component, however most
141
143
142
144
Since it's just a component, it works with `<transition>` and `<keep-alive>`. When using the both together, make sure to use `<keep-alive>` inside:
143
145
144
-
```html
146
+
```html
145
147
<transition>
146
148
<keep-alive>
147
149
<router-view></router-view>
@@ -166,22 +168,22 @@ Since it's just a component, it works with `<transition>` and `<keep-alive>`. Wh
166
168
167
169
Type declaration for `RouteConfig`:
168
170
169
-
```js
170
-
declare type RouteConfig = {
171
-
path: string;
172
-
component?: Component;
173
-
name?: string;// for named routes
174
-
components?: { [name: string]: Component };// for named views
@@ -338,7 +346,7 @@ Returns an Array of the components (definition/constructor, not instances) match
338
346
339
347
Signature:
340
348
341
-
```js
349
+
```js
342
350
const resolved: {
343
351
location:Location;
344
352
route: Route;
@@ -355,7 +363,7 @@ Reverse URL resolving. Given location in form same as used in `<router-link/>`.
355
363
356
364
Signature:
357
365
358
-
```js
366
+
```js
359
367
router.addRoutes(routes:Array<RouteConfig>)
360
368
```
361
369
@@ -365,7 +373,7 @@ Dynamically add more routes to the router. The argument must be an Array using t
365
373
366
374
Signature:
367
375
368
-
```js
376
+
```js
369
377
router.onReady(callback, [errorCallback])
370
378
```
371
379
@@ -379,7 +387,7 @@ The second argument `errorCallback` is only supported in 2.4+. It will be called
379
387
380
388
Signature:
381
389
382
-
```js
390
+
```js
383
391
router.onError(callback)
384
392
```
385
393
@@ -407,65 +415,67 @@ The route object can be found in multiple places:
407
415
408
416
- Inside navigation guards as the first two arguments:
409
417
410
-
```js
418
+
```js
411
419
router.beforeEach((to, from, next) => {
412
420
// `to` and `from` are both route objects
413
421
})
414
422
```
415
423
416
424
- Inside the `scrollBehavior` function as the first two arguments:
417
425
418
-
```js
426
+
```js
419
427
constrouter=newVueRouter({
420
-
scrollBehavior(to, from, savedPosition) {
428
+
scrollBehavior(to, from, savedPosition) {
421
429
// `to` and `from` are both route objects
422
430
}
423
431
})
424
432
```
425
433
426
434
### Route Object Properties
427
435
428
-
- **$route.path**
436
+
- **\$route.path**
429
437
430
438
- type: `string`
431
439
432
440
A string that equals the path of the current route, always resolved as an absolute path. e.g. `"/foo/bar"`.
433
441
434
-
- **$route.params**
442
+
- **\$route.params**
435
443
436
444
- type: `Object`
437
445
438
446
An object that contains key/value pairs of dynamic segments and star segments. If there are no params the value will be an empty object.
439
447
440
-
- **$route.query**
448
+
- **\$route.query**
441
449
442
450
- type: `Object`
443
451
444
452
An object that contains key/value pairs of the query string. For example, for a path `/foo?user=1`, we get `$route.query.user==1`. If there is no query the value will be an empty object.
445
453
446
-
- **$route.hash**
454
+
- **\$route.hash**
447
455
448
456
- type: `string`
449
457
450
458
The hash of the current route (with the `#`), if it has one. If no hash is present the value will be an empty string.
451
459
452
-
- **$route.fullPath**
460
+
- **\$route.fullPath**
453
461
454
462
- type: `string`
455
463
456
464
The full resolved URL including query and hash.
457
465
458
-
- **$route.matched**
466
+
- **\$route.matched**
459
467
460
468
- type: `Array<RouteRecord>`
461
469
462
470
An Array containing **route records** for all nested path segments of the current route. Route records are the copies of the objects in the `routes` configuration Array (and in `children` Arrays):
463
471
464
-
```js
472
+
```js
465
473
constrouter=newVueRouter({
466
474
routes: [
467
475
// the following object is a route record
468
-
{ path:'/foo', component: Foo,
476
+
{
477
+
path:'/foo',
478
+
component: Foo,
469
479
children: [
470
480
// this is also a route record
471
481
{ path:'bar', component: Bar }
@@ -477,11 +487,11 @@ The route object can be found in multiple places:
477
487
478
488
When the URL is `/foo/bar`, `$route.matched` will be an Array containing both objects (cloned), in parent to child order.
479
489
480
-
- **$route.name**
490
+
- **\$route.name**
481
491
482
492
The name of the current route, if it has one. (See [Named Routes](../guide/essentials/named-routes.md))
483
493
484
-
- **$route.redirectedFrom**
494
+
- **\$route.redirectedFrom**
485
495
486
496
The name of the route being redirected from, if there were one. (See [Redirect and Alias](../guide/essentials/redirect-and-alias.md))
487
497
@@ -491,11 +501,11 @@ The route object can be found in multiple places:
491
501
492
502
These properties are injected into every child component by passing the router instance to the root instance as the `router` option.
493
503
494
-
- **this.$router**
504
+
- **this.\$router**
495
505
496
506
The router instance.
497
507
498
-
- **this.$route**
508
+
- **this.\$route**
499
509
500
510
The current active [Route](#the-route-object). This property is read-only and its properties are immutable, but it can be watched.
0 commit comments