Skip to content

Commit 991a340

Browse files
committed
docs: format
1 parent d907a13 commit 991a340

File tree

1 file changed

+55
-45
lines changed

1 file changed

+55
-45
lines changed

docs/api/README.md

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ sidebar: auto
2222

2323
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:
2424

25-
``` html
25+
```html
2626
<router-link tag="li" to="/foo">
2727
<a>/foo</a>
2828
</router-link>
@@ -39,7 +39,7 @@ In this case the `<a>` will be the actual link (and will get the correct `href`)
3939

4040
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.
4141

42-
``` html
42+
```html
4343
<!-- literal string -->
4444
<router-link to="home">Home</router-link>
4545
<!-- renders to -->
@@ -58,7 +58,9 @@ In this case the `<a>` will be the actual link (and will get the correct `href`)
5858
<router-link :to="{ name: 'user', params: { userId: 123 }}">User</router-link>
5959

6060
<!-- with query, resulting in `/register?plan=private` -->
61-
<router-link :to="{ path: 'register', query: { plan: 'private' }}">Register</router-link>
61+
<router-link :to="{ path: 'register', query: { plan: 'private' }}"
62+
>Register</router-link
63+
>
6264
```
6365

6466
### replace
@@ -68,7 +70,7 @@ In this case the `<a>` will be the actual link (and will get the correct `href`)
6870

6971
Setting `replace` prop will call `router.replace()` instead of `router.push()` when clicked, so the navigation will not leave a history record.
7072

71-
``` html
73+
```html
7274
<router-link :to="{ path: '/abc'}" replace></router-link>
7375
```
7476

@@ -79,7 +81,7 @@ In this case the `<a>` will be the actual link (and will get the correct `href`)
7981

8082
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`.
8183

82-
``` html
84+
```html
8385
<router-link :to="{ path: 'relative/path'}" append></router-link>
8486
```
8587

@@ -90,7 +92,7 @@ In this case the `<a>` will be the actual link (and will get the correct `href`)
9092

9193
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.
9294

93-
``` html
95+
```html
9496
<router-link to="/foo" tag="li">foo</router-link>
9597
<!-- renders as -->
9698
<li>foo</li>
@@ -112,9 +114,9 @@ In this case the `<a>` will be the actual link (and will get the correct `href`)
112114

113115
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:
114116

115-
``` html
117+
```html
116118
<!-- this link will only be active at `/` -->
117-
<router-link to="/" exact>
119+
<router-link to="/" exact></router-link>
118120
```
119121

120122
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
141143

142144
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:
143145

144-
``` html
146+
```html
145147
<transition>
146148
<keep-alive>
147149
<router-view></router-view>
@@ -166,22 +168,22 @@ Since it's just a component, it works with `<transition>` and `<keep-alive>`. Wh
166168

167169
Type declaration for `RouteConfig`:
168170

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
175-
redirect?: string | Location | Function;
176-
props?: boolean | Object | Function;
177-
alias?: string | Array<string>;
178-
children?: Array<RouteConfig>; // for nested routes
179-
beforeEnter?: (to: Route, from: Route, next: Function) => void;
180-
meta?: any;
171+
```ts
172+
interface RouteConfig = {
173+
path: string,
174+
component?: Component,
175+
name?: string, // for named routes
176+
components?: { [name: string]: Component }, // for named views
177+
redirect?: string | Location | Function,
178+
props?: boolean | Object | Function,
179+
alias?: string | Array<string>,
180+
children?: Array<RouteConfig>, // for nested routes
181+
beforeEnter?: (to: Route, from: Route, next: Function) => void,
182+
meta?: any,
181183

182184
// 2.6.0+
183-
caseSensitive?: boolean; // use case sensitive match? (default: false)
184-
pathToRegexpOptions?: Object; // path-to-regexp options for compiling regex
185+
caseSensitive?: boolean, // use case sensitive match? (default: false)
186+
pathToRegexpOptions?: Object // path-to-regexp options for compiling regex
185187
}
186188
```
187189

@@ -285,12 +287,14 @@ Since it's just a component, it works with `<transition>` and `<keep-alive>`. Wh
285287
## Router Instance Methods
286288

287289
### router.beforeEach
290+
288291
### router.beforeResolve
292+
289293
### router.afterEach
290294

291295
Signatures:
292296

293-
``` js
297+
```js
294298
router.beforeEach((to, from, next) => {
295299
/* must call `next` */
296300
})
@@ -307,14 +311,18 @@ Add global navigation guards. See [Navigation Guards](../guide/advanced/navigati
307311
All three methods return a function that removes the registered guard/hook.
308312

309313
### router.push
314+
310315
### router.replace
316+
311317
### router.go
318+
312319
### router.back
320+
313321
### router.forward
314322

315323
Signatures:
316324

317-
``` js
325+
```js
318326
router.push(location, onComplete?, onAbort?)
319327
router.replace(location, onComplete?, onAbort?)
320328
router.go(n)
@@ -328,7 +336,7 @@ Programmatically navigate to a new URL. See [Programmatic Navigation](../guide/e
328336
329337
Signature:
330338
331-
``` js
339+
```js
332340
const matchedComponents: Array<Component> = router.getMatchedComponents(location?)
333341
```
334342
@@ -338,7 +346,7 @@ Returns an Array of the components (definition/constructor, not instances) match
338346
339347
Signature:
340348
341-
``` js
349+
```js
342350
const resolved: {
343351
location: Location;
344352
route: Route;
@@ -355,7 +363,7 @@ Reverse URL resolving. Given location in form same as used in `<router-link/>`.
355363
356364
Signature:
357365
358-
``` js
366+
```js
359367
router.addRoutes(routes: Array<RouteConfig>)
360368
```
361369
@@ -365,7 +373,7 @@ Dynamically add more routes to the router. The argument must be an Array using t
365373
366374
Signature:
367375
368-
``` js
376+
```js
369377
router.onReady(callback, [errorCallback])
370378
```
371379
@@ -379,7 +387,7 @@ The second argument `errorCallback` is only supported in 2.4+. It will be called
379387
380388
Signature:
381389
382-
``` js
390+
```js
383391
router.onError(callback)
384392
```
385393
@@ -407,65 +415,67 @@ The route object can be found in multiple places:
407415
408416
- Inside navigation guards as the first two arguments:
409417
410-
``` js
418+
```js
411419
router.beforeEach((to, from, next) => {
412420
// `to` and `from` are both route objects
413421
})
414422
```
415423
416424
- Inside the `scrollBehavior` function as the first two arguments:
417425
418-
``` js
426+
```js
419427
const router = new VueRouter({
420-
scrollBehavior (to, from, savedPosition) {
428+
scrollBehavior(to, from, savedPosition) {
421429
// `to` and `from` are both route objects
422430
}
423431
})
424432
```
425433
426434
### Route Object Properties
427435
428-
- **$route.path**
436+
- **\$route.path**
429437
430438
- type: `string`
431439
432440
A string that equals the path of the current route, always resolved as an absolute path. e.g. `"/foo/bar"`.
433441
434-
- **$route.params**
442+
- **\$route.params**
435443
436444
- type: `Object`
437445
438446
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.
439447
440-
- **$route.query**
448+
- **\$route.query**
441449
442450
- type: `Object`
443451
444452
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.
445453
446-
- **$route.hash**
454+
- **\$route.hash**
447455
448456
- type: `string`
449457
450458
The hash of the current route (with the `#`), if it has one. If no hash is present the value will be an empty string.
451459
452-
- **$route.fullPath**
460+
- **\$route.fullPath**
453461
454462
- type: `string`
455463
456464
The full resolved URL including query and hash.
457465
458-
- **$route.matched**
466+
- **\$route.matched**
459467
460468
- type: `Array<RouteRecord>`
461469
462470
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):
463471
464-
``` js
472+
```js
465473
const router = new VueRouter({
466474
routes: [
467475
// the following object is a route record
468-
{ path: '/foo', component: Foo,
476+
{
477+
path: '/foo',
478+
component: Foo,
469479
children: [
470480
// this is also a route record
471481
{ path: 'bar', component: Bar }
@@ -477,11 +487,11 @@ The route object can be found in multiple places:
477487
478488
When the URL is `/foo/bar`, `$route.matched` will be an Array containing both objects (cloned), in parent to child order.
479489
480-
- **$route.name**
490+
- **\$route.name**
481491
482492
The name of the current route, if it has one. (See [Named Routes](../guide/essentials/named-routes.md))
483493
484-
- **$route.redirectedFrom**
494+
- **\$route.redirectedFrom**
485495
486496
The name of the route being redirected from, if there were one. (See [Redirect and Alias](../guide/essentials/redirect-and-alias.md))
487497
@@ -491,11 +501,11 @@ The route object can be found in multiple places:
491501
492502
These properties are injected into every child component by passing the router instance to the root instance as the `router` option.
493503
494-
- **this.$router**
504+
- **this.\$router**
495505
496506
The router instance.
497507
498-
- **this.$route**
508+
- **this.\$route**
499509
500510
The current active [Route](#the-route-object). This property is read-only and its properties are immutable, but it can be watched.
501511

0 commit comments

Comments
 (0)