|
1 | | -import Vue, { ComponentOptions, PluginFunction, AsyncComponent } from 'vue' |
| 1 | +import Vue, { VNode, ComponentOptions, PluginFunction, AsyncComponent } from 'vue' |
| 2 | + |
| 3 | +export interface RouterLinkProps { |
| 4 | + /** |
| 5 | + * 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. |
| 6 | + */ |
| 7 | + to: string | Location |
| 8 | + /** |
| 9 | + * Setting `replace` prop will call `router.replace()` instead of `router.push()` when clicked, so the navigation will not leave a history record. |
| 10 | + * |
| 11 | + * @default false |
| 12 | + */ |
| 13 | + replace?: boolean |
| 14 | + /** |
| 15 | + * 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`. |
| 16 | + * |
| 17 | + * @default false |
| 18 | + */ |
| 19 | + append?: boolean |
| 20 | + /** |
| 21 | + * Sometimes we want <RouterLink> 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. |
| 22 | + * |
| 23 | + * @default "a" |
| 24 | + */ |
| 25 | + tag?: string |
| 26 | + /** |
| 27 | + * Configure the active CSS class applied when the link is active. Note the default value can also be configured globally via the `linkActiveClass` router constructor option. |
| 28 | + * |
| 29 | + * @default "router-link-active" |
| 30 | + */ |
| 31 | + activeClass?: string |
| 32 | + /** |
| 33 | + * The default active class matching behavior is **inclusive match**. For example, `<RouterLink to="/a">` will get this class applied as long as the current path starts with `/a/` or is `/a`. |
| 34 | + * |
| 35 | + * @default false |
| 36 | + */ |
| 37 | + exact?: boolean |
| 38 | + /** |
| 39 | + * Allows matching only using the `path` section of the url, effectively ignoring the `query` and the `hash` sections. |
| 40 | + * |
| 41 | + * @default false |
| 42 | + */ |
| 43 | + exactPath?: boolean |
| 44 | + /** |
| 45 | + * Configure the active CSS class applied when the link is active with exact path match. Note the default value can also be configured globally via the `linkExactPathActiveClass` router constructor option. |
| 46 | + * |
| 47 | + * @default "router-link-exact-path-active" |
| 48 | + */ |
| 49 | + exactPathActiveClass?: string |
| 50 | + |
| 51 | + /** |
| 52 | + * Specify the event(s) that can trigger the link navigation. |
| 53 | + * |
| 54 | + * @default 'click' |
| 55 | + */ |
| 56 | + event?: string | ReadonlyArray<string> |
| 57 | + /** |
| 58 | + * Configure the active CSS class applied when the link is active with exact match. Note the default value can also be configured globally via the `linkExactActiveClass` router constructor option. |
| 59 | + * |
| 60 | + * @default "router-link-exact-active" |
| 61 | + */ |
| 62 | + exactActiveClass?: string |
| 63 | + /** |
| 64 | + * Configure the value of `aria-current` when the link is active with exact match. It must be one of the allowed values for [aria-current](https://www.w3.org/TR/wai-aria-1.2/#aria-current) in the ARIA spec. In most cases, the default of page should be the best fit. |
| 65 | + * |
| 66 | + * @default "page" |
| 67 | + */ |
| 68 | + ariaCurrentValue?: |
| 69 | + | 'page' |
| 70 | + | 'step' |
| 71 | + | 'location' |
| 72 | + | 'date' |
| 73 | + | 'time' |
| 74 | + | 'true' |
| 75 | + | 'false' |
| 76 | +} |
| 77 | + |
| 78 | +interface RouterLinkSlotArgument { |
| 79 | + /** |
| 80 | + * resolved url. This would be the `href` attribute of an `a` element |
| 81 | + */ |
| 82 | + href: string |
| 83 | + /** |
| 84 | + * resolved normalized location |
| 85 | + */ |
| 86 | + route: Route |
| 87 | + /** |
| 88 | + * function to trigger the navigation. It will automatically prevent events when necessary, the same way `RouterLink` does |
| 89 | + */ |
| 90 | + navigate: (e?: MouseEvent) => Promise<void | NavigationFailure> |
| 91 | + /** |
| 92 | + * `true` if the [active class](https://router.vuejs.org/api/#active-class) should be applied. Allows to apply an arbitrary class |
| 93 | + */ |
| 94 | + isActive: boolean |
| 95 | + /** |
| 96 | + * `true` if the [exact active class](https://router.vuejs.org/api/#exact-active-class) should be applied. Allows to apply an arbitrary class |
| 97 | + */ |
| 98 | + isExactActive: boolean |
| 99 | +} |
| 100 | +/** |
| 101 | + * Component to render a link that triggers a navigation on click. |
| 102 | + */ |
| 103 | +declare const RouterLink: new (props:RouterLinkProps) => { |
| 104 | + $props: typeof props |
| 105 | + $scopedSlots: { |
| 106 | + default: ({ |
| 107 | + href, |
| 108 | + route, |
| 109 | + navigate, |
| 110 | + isActive, |
| 111 | + isExactActive |
| 112 | + }: RouterLinkSlotArgument) => VNode[] |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +export interface RouterViewProps { |
| 117 | + /** |
| 118 | + * When a <RouterView> has a name, it will render the component with the corresponding name in the matched route record's components option. See [Named Views](https://router.vuejs.org/guide/essentials/named-views.html) for an example. |
| 119 | + * |
| 120 | + * @default "default" |
| 121 | + */ |
| 122 | + name?: string |
| 123 | +} |
| 124 | + |
| 125 | +/** |
| 126 | + * Component to display the current route the user is at. |
| 127 | + */ |
| 128 | +declare const RouterView: new (props: RouterViewProps) => { |
| 129 | + $props: typeof props |
| 130 | +} |
2 | 131 |
|
3 | 132 | type Component = ComponentOptions<Vue> | typeof Vue | AsyncComponent |
4 | 133 | type Dictionary<T> = { [key: string]: T } |
@@ -78,6 +207,16 @@ export declare class VueRouter { |
78 | 207 | } |
79 | 208 |
|
80 | 209 | static START_LOCATION: Route |
| 210 | + |
| 211 | + /** |
| 212 | + * Component to render a link that triggers a navigation on click. |
| 213 | + */ |
| 214 | + static readonly RouterLink: typeof RouterLink |
| 215 | + |
| 216 | + /** |
| 217 | + * Component to display the current route the user is at. |
| 218 | + */ |
| 219 | + static readonly RouterView: typeof RouterView |
81 | 220 | } |
82 | 221 |
|
83 | 222 | export enum NavigationFailureType { |
|
0 commit comments