Skip to content

Commit

Permalink
docs: fix links
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jun 11, 2024
1 parent 57601c0 commit 51f0182
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 60 deletions.
4 changes: 2 additions & 2 deletions packages/docs/guide/advanced/navigation-guards.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Global before guards are called in creation order, whenever a navigation is trig

Every guard function receives two arguments:

- **`to`**: the target route location [in a normalized format](../../api/interfaces/RouteLocationNormalized.md) being navigated to.
- **`from`**: the current route location [in a normalized format](../../api/interfaces/RouteLocationNormalized.md) being navigated away from.
- **`to`**: the target route location [in a normalized format](../../api/#RouteLocationNormalized) being navigated to.
- **`from`**: the current route location [in a normalized format](../../api/#RouteLocationNormalized) being navigated away from.

And can optionally return any of the following values:

Expand Down
14 changes: 7 additions & 7 deletions packages/docs/guide/essentials/active-links.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ The RouterLink component adds two CSS classes to active links, `router-link-acti

## When are links active?

A RouterLink is considered to be ***active*** if:
A RouterLink is considered to be **_active_** if:

1. It matches the same route record (i.e. configured route) as the current location.
2. It has the same values for the `params` as the current location.

If you're using [nested routes](./nested-routes), any links to ancestor routes will also be considered active if the relevant `params` match.

Other route properties, such as the [`query`](../../api/interfaces/RouteLocationNormalized#query), are not taken into account.
Other route properties, such as the [`query`](../../api/interfaces/RouteLocationBase.html#query), are not taken into account.

The path doesn't necessarily need to be a perfect match. For example, using an [`alias`](./redirect-and-alias#Alias) would still be considered a match, so long as it resolves to the same route record and `params`.

If a route has a [`redirect`](./redirect-and-alias#Redirect), it won't be followed when checking whether a link is active.

## Exact active links

An ***exact*** match does not include ancestor routes.
An **_exact_** match does not include ancestor routes.

Let's imagine we have the following routes:

Expand All @@ -34,9 +34,9 @@ const routes = [
{
path: 'role/:roleId',
component: Role,
}
]
}
},
],
},
]
```

Expand All @@ -51,7 +51,7 @@ Then consider these two links:
</RouterLink>
```

If the current location path is `/user/erina/role/admin` then these would both be considered _active_, so the class `router-link-active` would be applied to both links. But only the second link would be considered _exact_, so only that second link would have the class `router-link-exact-active`.
If the current location path is `/user/erina/role/admin` then these would both be considered _active_, so the class `router-link-active` would be applied to both links. But only the second link would be considered _exact_, so only that second link would have the class `router-link-exact-active`.

## Configuring the classes

Expand Down
17 changes: 10 additions & 7 deletions packages/docs/guide/essentials/dynamic-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ A _param_ is denoted by a colon `:`. When a route is matched, the value of its _

You can have multiple _params_ in the same route, and they will map to corresponding fields on `route.params`. Examples:

| pattern | matched path | route.params |
| ------------------------------ | ------------------------ | -------------------------------------- |
| /users/:username | /users/eduardo | `{ username: 'eduardo' }` |
| pattern | matched path | route.params |
| ------------------------------ | ------------------------ | ---------------------------------------- |
| /users/:username | /users/eduardo | `{ username: 'eduardo' }` |
| /users/:username/posts/:postId | /users/eduardo/posts/123 | `{ username: 'eduardo', postId: '123' }` |

In addition to `route.params`, the `route` object also exposes other useful information such as `route.query` (if there is a query in the URL), `route.hash`, etc. You can check out the full details in the [API Reference](../../api/interfaces/RouteLocationNormalized.md).
In addition to `route.params`, the `route` object also exposes other useful information such as `route.query` (if there is a query in the URL), `route.hash`, etc. You can check out the full details in the [API Reference](../../api/#RouteLocationNormalized).

A working demo of this example can be found [here](https://codesandbox.io/s/route-params-vue-router-examples-mlb14?from-embed&initialpath=%2Fusers%2Feduardo%2Fposts%2F1).

Expand Down Expand Up @@ -69,9 +69,12 @@ import { useRoute } from 'vue-router'
const route = useRoute()
watch(() => route.params.id, (newId, oldId) => {
// react to route changes...
})
watch(
() => route.params.id,
(newId, oldId) => {
// react to route changes...
}
)
</script>
```

Expand Down
2 changes: 1 addition & 1 deletion packages/docs/guide/migration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ Note this will work if `path` was `/parent/` as the relative location `home` to

Decoded values in `params`, `query`, and `hash` are now consistent no matter where the navigation is initiated (older browsers will still produce unencoded `path` and `fullPath`). The initial navigation should yield the same results as in-app navigations.

Given any [normalized route location](/api/interfaces/RouteLocationNormalized.md):
Given any [normalized route location](/api/#RouteLocationNormalized):

- Values in `path`, `fullPath` are not decoded anymore. They will appear as provided by the browser (most browsers provide them encoded). e.g. directly writing on the address bar `https://example.com/hello world` will yield the encoded version: `https://example.com/hello%20world` and both `path` and `fullPath` will be `/hello%20world`.
- `hash` is now decoded, that way it can be copied over: `router.push({ hash: $route.hash })` and be used directly in [scrollBehavior](/api/interfaces/RouterOptions.md#scrollBehavior)'s `el` option.
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/typedoc-markdown.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const __dirname = path.dirname(new URL(import.meta.url).pathname)
const DEFAULT_OPTIONS = {
// disableOutputCheck: true,
cleanOutputDir: true,
excludeInternal: true,
excludeInternal: false,
readme: 'none',
out: path.resolve(__dirname, './api'),
entryDocument: 'index.md',
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/zh/guide/migration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ createRouter({
})
```

**原因**: Vue支持的所有浏览器都支持 [HTML5 History API](https://developer.mozilla.org/zh-CN/docs/Web/API/History_API),因此我们不再需要使用 `location.hash`,而可以直接使用 `history.pushState()`
**原因**: Vue 支持的所有浏览器都支持 [HTML5 History API](https://developer.mozilla.org/zh-CN/docs/Web/API/History_API),因此我们不再需要使用 `location.hash`,而可以直接使用 `history.pushState()`

### 删除了 `*`(星标或通配符)路由

Expand Down Expand Up @@ -436,7 +436,7 @@ const routes = [

<!-- TODO: translate chinese API entries -->

给定任何[规范化的路由地址](/zh/api/interfaces/RouteLocationNormalized.md):
给定任何[规范化的路由地址](/zh/api/#RouteLocationNormalized):

- `path`, `fullPath`中的值不再被解码了。例如,直接在地址栏上写 "<https://example.com/hello> world",将得到编码后的版本:"https://example.com/hello%20world",而 "path "和 "fullPath "都是"/hello%20world"。
- `hash` 现在被解码了,这样就可以复制过来。`router.push({ hash: $route.hash })` 可以直接用于 [scrollBehavior](/zh/api/interfaces/RouterOptions.md#Properties-scrollBehavior)`el` 配置中。
Expand Down
39 changes: 39 additions & 0 deletions packages/router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,59 @@ export type {
RouteMeta,
RouteComponent,
// RawRouteComponent,
RouteParamsGeneric,
RouteParamsRawGeneric,
MatcherLocation,
} from './types'
export type { _Awaitable } from './types/utils'

// Experimental Type Safe API
export type {
RouteMap,
RouteMapGeneric,

// route location
RouteLocationRaw,
RouteLocation,
RouteLocationTyped,
RouteLocationTypedList,
RouteLocationGeneric,

// RouteLocationNormalized
RouteLocationNormalizedGeneric,
RouteLocationNormalized,
RouteLocationNormalizedTyped,
RouteLocationNormalizedTypedList,

// RouteLocationNormalizedLoaded
RouteLocationNormalizedLoadedGeneric,
RouteLocationNormalizedLoaded,
RouteLocationNormalizedLoadedTyped,
RouteLocationNormalizedLoadedTypedList,

// RouteLocationResolved
RouteLocationResolved,
RouteLocationResolvedGeneric,
RouteLocationResolvedTyped,
RouteLocationResolvedTypedList,

// relative
RouteLocationAsRelative,
RouteLocationAsRelativeGeneric,
RouteLocationAsRelativeTyped,
RouteLocationAsRelativeTypedList,
// string
RouteLocationAsString,
// as path
RouteLocationAsPathGeneric,
RouteLocationAsPathTyped,
RouteLocationAsPathTypedList,

// route records
RouteRecordInfo,
RouteRecordName,
RouteRecordNameGeneric,
_RouteRecordProps,
RouteRecordRedirectOption,

// params
Expand All @@ -92,6 +130,7 @@ export type {
NavigationHookAfter,
NavigationGuardReturn,
NavigationGuardNext,
NavigationGuardNextCallback,
} from './typed-routes'

export { createRouter } from './router'
Expand Down
41 changes: 5 additions & 36 deletions packages/router/src/typed-routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,5 @@
export type {
ParamValue,
ParamValueOneOrMore,
ParamValueZeroOrMore,
ParamValueZeroOrOne,
RouteParams,
RouteParamsRaw,
} from './params'

export type { RouteRecordInfo } from './route-map'

export type {
RouteRecordName,
RouteLocationRaw,
RouteLocation,
RouteLocationNormalized,
RouteLocationNormalizedGeneric,
RouteLocationNormalizedLoaded,
RouteLocationResolved,
RouteLocationAsRelative,
} from './route-location'

export type {
RouteRecordRedirectOption,
RouteRecordNameGeneric,
_RouteRecordProps,
} from './route-records'

export type {
NavigationGuard,
NavigationGuardReturn,
NavigationHookAfter,
NavigationGuardWithThis,
NavigationGuardNext,
NavigationGuardNextCallback,
} from './navigation-guards'
export type * from './params'
export type * from './route-map'
export type * from './route-location'
export type * from './route-records'
export type * from './navigation-guards'
6 changes: 2 additions & 4 deletions packages/router/src/typed-routes/route-location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export type RouteLocation<Name extends keyof RouteMap = keyof RouteMap> =

/**
* Similar to {@link RouteLocation} but its
* {@link RouteLocationNormalizedTyped.matched `matched` property} cannot contain redirect records
* {@link RouteLocationNormalizedTyped.matched | `matched` property} cannot contain redirect records
*/
export type RouteLocationNormalized<
Name extends keyof RouteMap = keyof RouteMap
Expand All @@ -251,7 +251,6 @@ export type RouteLocationNormalized<
/**
* Similar to {@link RouteLocationNormalized} but its `components` do not contain any function to lazy load components.
* In other words, it's ready to be rendered by `<RouterView>`.
* @see {@link RouteLocationNormalized}
*/
export type RouteLocationNormalizedLoaded<
Name extends keyof RouteMap = keyof RouteMap
Expand All @@ -270,8 +269,7 @@ export type RouteLocationAsRelative<
: RouteLocationAsRelativeTypedList<RouteMap>[Name]

/**
* Route location resolved with `router.resolve()`.
* @see {@link Router['resolve'] | `router.resolve()`}
* Route location resolved with {@link Router | `router.resolve()`}.
*/
export type RouteLocationResolved<
Name extends keyof RouteMap = keyof RouteMap
Expand Down

0 comments on commit 51f0182

Please sign in to comment.