From 57d8727d4dbb2dac7a73b353170b9dc26ba4351d Mon Sep 17 00:00:00 2001 From: skirtle <65301168+skirtles-code@users.noreply.github.com> Date: Fri, 15 Dec 2023 06:14:29 +0000 Subject: [PATCH 001/164] docs: expand installation.md (#2071) --- packages/docs/installation.md | 42 ++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/packages/docs/installation.md b/packages/docs/installation.md index 5503d5ceb..6677e33b8 100644 --- a/packages/docs/installation.md +++ b/packages/docs/installation.md @@ -12,14 +12,46 @@ -## npm +This will expose Vue Router via a global `VueRouter` object, e.g. `VueRouter.createRouter(...)`. -```bash +## Package managers + +If you have an existing project that uses a JavaScript package manager, you can install Vue Router from the npm registry: + +::: code-group + +```bash [npm] npm install vue-router@4 ``` -## yarn - -```bash +```bash [yarn] yarn add vue-router@4 ``` + +```bash [pnpm] +pnpm add vue-router@4 +``` + +::: + +If you're starting a new project, you might find it easier to use the [create-vue](https://github.com/vuejs/create-vue) scaffolding tool, which creates a Vite-based project with the option to include Vue Router: + +::: code-group + +```bash [npm] +npm create vue@latest +``` + +```bash [yarn] +yarn create vue +``` + +```bash [pnpm] +pnpm create vue +``` + +::: + +You'll be prompted with some questions about the kind of project you want to create. If you choose to install Vue Router, the example application will also demonstrate some of Vue Router's core features. + +Projects using package managers will typically use ES modules to access Vue Router, e.g. `import { createRouter } from 'vue-router'`. \ No newline at end of file From 3c91f0f776807712248ffb4fe0d3902edff37f26 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Fri, 15 Dec 2023 14:18:08 +0800 Subject: [PATCH 002/164] docs: translate `Caveat` in `zh` (#1921) --- packages/docs/zh/guide/essentials/history-mode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docs/zh/guide/essentials/history-mode.md b/packages/docs/zh/guide/essentials/history-mode.md index 8334552af..edc44085c 100644 --- a/packages/docs/zh/guide/essentials/history-mode.md +++ b/packages/docs/zh/guide/essentials/history-mode.md @@ -186,7 +186,7 @@ rewrite { } ``` -## Caveat +## 附加说明 这有一个注意事项。你的服务器将不再报告 404 错误,因为现在所有未找到的路径都会显示你的 `index.html` 文件。为了解决这个问题,你应该在你的 Vue 应用程序中实现一个万能的路由来显示 404 页面。 From 8b59f868395db50a2c76579aa297c59e1f72e878 Mon Sep 17 00:00:00 2001 From: Satrong Date: Fri, 15 Dec 2023 15:09:59 +0800 Subject: [PATCH 003/164] docs(zh): additions `setData` method (#2008) --- packages/docs/zh/guide/advanced/data-fetching.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/docs/zh/guide/advanced/data-fetching.md b/packages/docs/zh/guide/advanced/data-fetching.md index e060fcfb7..521a6396f 100644 --- a/packages/docs/zh/guide/advanced/data-fetching.md +++ b/packages/docs/zh/guide/advanced/data-fetching.md @@ -82,6 +82,7 @@ export default { }, beforeRouteEnter(to, from, next) { getPost(to.params.id, (err, post) => { + // `setData` 方法定义在下面的代码中 next(vm => vm.setData(err, post)) }) }, @@ -95,6 +96,15 @@ export default { this.error = error.toString() } }, + methods: { + setData(error, post) { + if (error) { + this.error = error + } else { + this.post = post + } + } + } } ``` From b298d56db5e81fc1b94c639f4b34349fdecddda2 Mon Sep 17 00:00:00 2001 From: MonsterPi <43134418+MonsterPi13@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:11:09 +0800 Subject: [PATCH 004/164] refactor: simplify location parsing (#1691) * chore: maybe it's unnecessary to add this expression * style: format code --- packages/router/src/location.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/router/src/location.ts b/packages/router/src/location.ts index ef85d359b..1f29cfb63 100644 --- a/packages/router/src/location.ts +++ b/packages/router/src/location.ts @@ -244,9 +244,6 @@ export function resolveRelativePath(to: string, from: string): string { return ( fromSegments.slice(0, position).join('/') + '/' + - toSegments - // ensure we use at least the last element in the toSegments - .slice(toPosition - (toPosition === toSegments.length ? 1 : 0)) - .join('/') + toSegments.slice(toPosition).join('/') ) } From 0ec4862ff54207c1c207027ed240e24efcfeb6cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99drzy=C5=84ski?= Date: Fri, 30 Jun 2023 10:36:52 +0200 Subject: [PATCH 005/164] fix: handle undefined path in router resolve --- packages/router/__tests__/router.spec.ts | 11 +++++++++++ packages/router/src/matcher/index.ts | 2 +- packages/router/src/router.ts | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/router/__tests__/router.spec.ts b/packages/router/__tests__/router.spec.ts index a60db5393..951f2f0db 100644 --- a/packages/router/__tests__/router.spec.ts +++ b/packages/router/__tests__/router.spec.ts @@ -319,6 +319,17 @@ describe('Router', () => { await router.push({ name: 'optional', params: {} }) }) + it('handles undefined path', async () => { + const { router } = await newRouter() + + const route1 = router.resolve({ + path: undefined, + params: { p: 'a' }, + }) + expect(route1.path).toBe('/') + expect(route1.params).toEqual({ p: 'a' }) + }) + it('removes null/undefined optional params when current location has it', async () => { const { router } = await newRouter() diff --git a/packages/router/src/matcher/index.ts b/packages/router/src/matcher/index.ts index 6c9a35d35..f7668dd5e 100644 --- a/packages/router/src/matcher/index.ts +++ b/packages/router/src/matcher/index.ts @@ -290,7 +290,7 @@ export function createRouterMatcher( ) // throws if cannot be stringified path = matcher.stringify(params) - } else if ('path' in location) { + } else if ('path' in location && location.path != null) { // no need to resolve the path with the matcher as it was provided // this also allows the user to control the encoding path = location.path diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts index 1d6c66975..e5beb1f1b 100644 --- a/packages/router/src/router.ts +++ b/packages/router/src/router.ts @@ -463,7 +463,7 @@ export function createRouter(options: RouterOptions): Router { let matcherLocation: MatcherLocationRaw // path could be relative in object as well - if ('path' in rawLocation) { + if ('path' in rawLocation && rawLocation.path != null) { if ( __DEV__ && 'params' in rawLocation && From bf48bcef209f3795c474bd03168be903a0305491 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Sun, 2 Jul 2023 23:38:20 +0200 Subject: [PATCH 006/164] refactor: code review and fixes --- packages/router/__tests__/warnings.spec.ts | 3 +++ packages/router/src/errors.ts | 2 +- packages/router/src/matcher/index.ts | 2 +- packages/router/src/router.ts | 8 ++++---- packages/router/src/types/index.ts | 6 ++++++ 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/router/__tests__/warnings.spec.ts b/packages/router/__tests__/warnings.spec.ts index f7be96237..82f6450d5 100644 --- a/packages/router/__tests__/warnings.spec.ts +++ b/packages/router/__tests__/warnings.spec.ts @@ -32,6 +32,7 @@ describe('warnings', () => { history, routes: [{ path: '/:p', name: 'p', component }], }) + // @ts-expect-error: cannot pass params with a path router.push({ path: '/p', params: { p: 'p' } }) expect('Path "/p" was passed with params').toHaveBeenWarned() }) @@ -42,6 +43,8 @@ describe('warnings', () => { history, routes: [{ path: '/:p', name: 'p', component }], }) + // @ts-expect-error: it would be better if this didn't error but it still an + // invalid location router.push({ path: '/p', name: 'p', params: { p: 'p' } }) expect('Path "/" was passed with params').not.toHaveBeenWarned() }) diff --git a/packages/router/src/errors.ts b/packages/router/src/errors.ts index 773be27be..379bf6392 100644 --- a/packages/router/src/errors.ts +++ b/packages/router/src/errors.ts @@ -190,7 +190,7 @@ const propertiesToLog = ['params', 'query', 'hash'] as const function stringifyRoute(to: RouteLocationRaw): string { if (typeof to === 'string') return to - if ('path' in to) return to.path + if (to.path != null) return to.path const location = {} as Record for (const key of propertiesToLog) { if (key in to) location[key] = to[key] diff --git a/packages/router/src/matcher/index.ts b/packages/router/src/matcher/index.ts index f7668dd5e..39a3c24b1 100644 --- a/packages/router/src/matcher/index.ts +++ b/packages/router/src/matcher/index.ts @@ -290,7 +290,7 @@ export function createRouterMatcher( ) // throws if cannot be stringified path = matcher.stringify(params) - } else if ('path' in location && location.path != null) { + } else if (location.path != null) { // no need to resolve the path with the matcher as it was provided // this also allows the user to control the encoding path = location.path diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts index e5beb1f1b..f5cc271ee 100644 --- a/packages/router/src/router.ts +++ b/packages/router/src/router.ts @@ -463,7 +463,7 @@ export function createRouter(options: RouterOptions): Router { let matcherLocation: MatcherLocationRaw // path could be relative in object as well - if ('path' in rawLocation && rawLocation.path != null) { + if (rawLocation.path != null) { if ( __DEV__ && 'params' in rawLocation && @@ -525,7 +525,7 @@ export function createRouter(options: RouterOptions): Router { } else if (!matchedRoute.matched.length) { warn( `No match found for location with path "${ - 'path' in rawLocation ? rawLocation.path : rawLocation + rawLocation.path != null ? rawLocation.path : rawLocation }"` ) } @@ -606,7 +606,7 @@ export function createRouter(options: RouterOptions): Router { if ( __DEV__ && - !('path' in newTargetLocation) && + newTargetLocation.path == null && !('name' in newTargetLocation) ) { warn( @@ -626,7 +626,7 @@ export function createRouter(options: RouterOptions): Router { query: to.query, hash: to.hash, // avoid transferring params if the redirect has a path - params: 'path' in newTargetLocation ? {} : to.params, + params: newTargetLocation.path != null ? {} : to.params, }, newTargetLocation ) diff --git a/packages/router/src/types/index.ts b/packages/router/src/types/index.ts index 346921224..b7e88db13 100644 --- a/packages/router/src/types/index.ts +++ b/packages/router/src/types/index.ts @@ -58,6 +58,8 @@ export interface MatcherLocationAsPath { */ export interface MatcherLocationAsName { name: RouteRecordName + // to allow checking location.path == null + path?: undefined params?: RouteParams } @@ -65,6 +67,8 @@ export interface MatcherLocationAsName { * @internal */ export interface MatcherLocationAsRelative { + // to allow checking location.path == null + path?: undefined params?: RouteParams } @@ -73,6 +77,8 @@ export interface MatcherLocationAsRelative { */ export interface LocationAsRelativeRaw { name?: RouteRecordName + // to allow checking location.path == null + path?: undefined params?: RouteParamsRaw } From 2607045f549dd134fdf860835207812e2b5cfcb5 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 5 Jul 2023 15:30:05 +0200 Subject: [PATCH 007/164] docs: undefined path --- packages/router/src/types/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/router/src/types/index.ts b/packages/router/src/types/index.ts index b7e88db13..9c2396b21 100644 --- a/packages/router/src/types/index.ts +++ b/packages/router/src/types/index.ts @@ -59,6 +59,9 @@ export interface MatcherLocationAsPath { export interface MatcherLocationAsName { name: RouteRecordName // to allow checking location.path == null + /** + * Ignored path property since we are dealing with a relative location. Only `undefined` is allowed. + */ path?: undefined params?: RouteParams } @@ -68,6 +71,9 @@ export interface MatcherLocationAsName { */ export interface MatcherLocationAsRelative { // to allow checking location.path == null + /** + * Ignored path property since we are dealing with a relative location. Only `undefined` is allowed. + */ path?: undefined params?: RouteParams } @@ -78,6 +84,9 @@ export interface MatcherLocationAsRelative { export interface LocationAsRelativeRaw { name?: RouteRecordName // to allow checking location.path == null + /** + * Ignored path property since we are dealing with a relative location. Only `undefined` is allowed. + */ path?: undefined params?: RouteParamsRaw } From 3b060f6b8ff79f7aae2b4bb2f50e1c5225a79173 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Fri, 15 Dec 2023 15:27:57 +0100 Subject: [PATCH 008/164] chore: up deps --- package.json | 2 +- packages/playground/package.json | 2 +- packages/router/package.json | 4 +- pnpm-lock.yaml | 159 ++++++++++++++++++++----------- 4 files changed, 110 insertions(+), 57 deletions(-) diff --git a/package.json b/package.json index 7fa38fa00..53fe65d15 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "semver": "^7.5.4", "typedoc": "^0.25.3", "typedoc-plugin-markdown": "^3.17.1", - "typescript": "~5.1.6", + "typescript": "~5.3.3", "yorkie": "^2.0.0" }, "gitHooks": { diff --git a/packages/playground/package.json b/packages/playground/package.json index d5c94b6e2..c978c1f43 100644 --- a/packages/playground/package.json +++ b/packages/playground/package.json @@ -16,7 +16,7 @@ "@vitejs/plugin-vue": "^4.5.2", "@vue/compiler-sfc": "^3.3.11", "@vue/tsconfig": "^0.4.0", - "typescript": "~5.1.6", + "typescript": "~5.3.3", "vite": "^5.0.7", "vue-router": "workspace:*", "vue-tsc": "^1.8.25" diff --git a/packages/router/package.json b/packages/router/package.json index b8f5211ea..d0f7d3f02 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -82,7 +82,7 @@ "@vue/devtools-api": "^6.5.1" }, "devDependencies": { - "@microsoft/api-extractor": "^7.36.4", + "@microsoft/api-extractor": "^7.38.5", "@rollup/plugin-alias": "^5.1.0", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-node-resolve": "^15.2.3", @@ -113,7 +113,7 @@ "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-typescript2": "^0.36.0", "sucrase": "^3.34.0", - "typescript": "~5.1.6", + "typescript": "~5.3.3", "vite": "^5.0.7", "vue": "^3.3.11" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6713db304..b137efc27 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -40,13 +40,13 @@ importers: version: 7.5.4 typedoc: specifier: ^0.25.3 - version: 0.25.4(typescript@5.1.6) + version: 0.25.4(typescript@5.3.3) typedoc-plugin-markdown: specifier: ^3.17.1 version: 3.17.1(typedoc@0.25.4) typescript: - specifier: ~5.1.6 - version: 5.1.6 + specifier: ~5.3.3 + version: 5.3.3 yorkie: specifier: ^2.0.0 version: 2.0.0 @@ -67,7 +67,7 @@ importers: dependencies: vue: specifier: ^3.3.11 - version: 3.3.11(typescript@5.1.6) + version: 3.3.11(typescript@5.3.3) devDependencies: '@types/node': specifier: ^20.10.4 @@ -82,8 +82,8 @@ importers: specifier: ^0.4.0 version: 0.4.0 typescript: - specifier: ~5.1.6 - version: 5.1.6 + specifier: ~5.3.3 + version: 5.3.3 vite: specifier: ^5.0.7 version: 5.0.9(@types/node@20.10.4) @@ -92,7 +92,7 @@ importers: version: link:../router vue-tsc: specifier: ^1.8.25 - version: 1.8.25(typescript@5.1.6) + version: 1.8.25(typescript@5.3.3) packages/router: dependencies: @@ -101,8 +101,8 @@ importers: version: 6.5.1 devDependencies: '@microsoft/api-extractor': - specifier: ^7.36.4 - version: 7.36.4 + specifier: ^7.38.5 + version: 7.38.5 '@rollup/plugin-alias': specifier: ^5.1.0 version: 5.1.0(rollup@3.29.4) @@ -189,19 +189,19 @@ importers: version: 4.0.0 rollup-plugin-typescript2: specifier: ^0.36.0 - version: 0.36.0(rollup@3.29.4)(typescript@5.1.6) + version: 0.36.0(rollup@3.29.4)(typescript@5.3.3) sucrase: specifier: ^3.34.0 version: 3.34.0 typescript: - specifier: ~5.1.6 - version: 5.1.6 + specifier: ~5.3.3 + version: 5.3.3 vite: specifier: ^5.0.7 version: 5.0.9(@types/node@20.10.4) vue: specifier: ^3.3.11 - version: 3.3.11(typescript@5.1.6) + version: 3.3.11(typescript@5.3.3) packages: @@ -1208,29 +1208,29 @@ packages: resolution: {integrity: sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==} dev: false - /@microsoft/api-extractor-model@7.27.6: - resolution: {integrity: sha512-eiCnlayyum1f7fS2nA9pfIod5VCNR1G+Tq84V/ijDrKrOFVa598BLw145nCsGDMoFenV6ajNi2PR5WCwpAxW6Q==} + /@microsoft/api-extractor-model@7.28.3: + resolution: {integrity: sha512-wT/kB2oDbdZXITyDh2SQLzaWwTOFbV326fP0pUwNW00WeliARs0qjmXBWmGWardEzp2U3/axkO3Lboqun6vrig==} dependencies: '@microsoft/tsdoc': 0.14.2 '@microsoft/tsdoc-config': 0.16.2 - '@rushstack/node-core-library': 3.59.7 + '@rushstack/node-core-library': 3.62.0 transitivePeerDependencies: - '@types/node' dev: true - /@microsoft/api-extractor@7.36.4: - resolution: {integrity: sha512-21UECq8C/8CpHT23yiqTBQ10egKUacIpxkPyYR7hdswo/M5yTWdBvbq+77YC9uPKQJOUfOD1FImBQ1DzpsdeQQ==} + /@microsoft/api-extractor@7.38.5: + resolution: {integrity: sha512-c/w2zfqBcBJxaCzpJNvFoouWewcYrUOfeu5ZkWCCIXTF9a/gXM85RGevEzlMAIEGM/kssAAZSXRJIZ3Q5vLFow==} hasBin: true dependencies: - '@microsoft/api-extractor-model': 7.27.6 + '@microsoft/api-extractor-model': 7.28.3 '@microsoft/tsdoc': 0.14.2 '@microsoft/tsdoc-config': 0.16.2 - '@rushstack/node-core-library': 3.59.7 - '@rushstack/rig-package': 0.4.1 - '@rushstack/ts-command-line': 4.15.2 + '@rushstack/node-core-library': 3.62.0 + '@rushstack/rig-package': 0.5.1 + '@rushstack/ts-command-line': 4.17.1 colors: 1.2.5 lodash: 4.17.21 - resolve: 1.22.4 + resolve: 1.22.8 semver: 7.5.4 source-map: 0.6.1 typescript: 5.0.4 @@ -1491,8 +1491,8 @@ packages: requiresBuild: true optional: true - /@rushstack/node-core-library@3.59.7: - resolution: {integrity: sha512-ln1Drq0h+Hwa1JVA65x5mlSgUrBa1uHL+V89FqVWQgXd1vVIMhrtqtWGQrhTnFHxru5ppX+FY39VWELF/FjQCw==} + /@rushstack/node-core-library@3.62.0: + resolution: {integrity: sha512-88aJn2h8UpSvdwuDXBv1/v1heM6GnBf3RjEy6ZPP7UnzHNCqOHA2Ut+ScYUbXcqIdfew9JlTAe3g+cnX9xQ/Aw==} peerDependencies: '@types/node': '*' peerDependenciesMeta: @@ -1503,20 +1503,20 @@ packages: fs-extra: 7.0.1 import-lazy: 4.0.0 jju: 1.4.0 - resolve: 1.22.4 + resolve: 1.22.8 semver: 7.5.4 z-schema: 5.0.5 dev: true - /@rushstack/rig-package@0.4.1: - resolution: {integrity: sha512-AGRwpqlXNSp9LhUSz4HKI9xCluqQDt/obsQFdv/NYIekF3pTTPzc+HbQsIsjVjYnJ3DcmxOREVMhvrMEjpiq6g==} + /@rushstack/rig-package@0.5.1: + resolution: {integrity: sha512-pXRYSe29TjRw7rqxD4WS3HN/sRSbfr+tJs4a9uuaSIBAITbUggygdhuG0VrO0EO+QqH91GhYMN4S6KRtOEmGVA==} dependencies: - resolve: 1.22.4 + resolve: 1.22.8 strip-json-comments: 3.1.1 dev: true - /@rushstack/ts-command-line@4.15.2: - resolution: {integrity: sha512-5+C2uoJY8b+odcZD6coEe2XNC4ZjGB4vCMESbqW/8DHRWC/qIHfANdmN9F1wz/lAgxz72i7xRoVtPY2j7e4gpQ==} + /@rushstack/ts-command-line@4.17.1: + resolution: {integrity: sha512-2jweO1O57BYP5qdBGl6apJLB+aRIn5ccIRTPDyULh0KMwVzFqWtw6IZWt1qtUoZD/pD2RNkIOosH6Cq45rIYeg==} dependencies: '@types/argparse': 1.0.38 argparse: 1.0.10 @@ -1777,8 +1777,8 @@ packages: '@types/yargs-parser': 21.0.0 dev: true - /@types/yauzl@2.10.0: - resolution: {integrity: sha512-Cn6WYCm0tXv8p6k+A8PvbDG763EDpBoTzHdA+Q/MF6H3sapGjCm9NzoaJncJS9tUKSuCoDs9XHxYYsQDgxR6kw==} + /@types/yauzl@2.10.3: + resolution: {integrity: sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==} requiresBuild: true dependencies: '@types/node': 20.10.4 @@ -1801,7 +1801,7 @@ packages: vue: ^3.2.25 dependencies: vite: 5.0.9(@types/node@20.10.4) - vue: 3.3.11(typescript@5.1.6) + vue: 3.3.11(typescript@5.3.3) /@volar/language-core@1.11.1: resolution: {integrity: sha512-dOcNn3i9GgZAcJt43wuaEykSluAuOkQgzni1cuxLxTV0nJKanQztp7FxyswdRILaKH+P2XZMPRp2S4MV/pElCw==} @@ -1876,7 +1876,7 @@ packages: resolution: {integrity: sha512-+KpckaAQyfbvshdDW5xQylLni1asvNSGme1JFs8I1+/H5pHEhqUKMEQD/qn3Nx5+/nycBq11qAEi8lk+LXI2dA==} dev: false - /@vue/language-core@1.8.25(typescript@5.1.6): + /@vue/language-core@1.8.25(typescript@5.3.3): resolution: {integrity: sha512-NJk/5DnAZlpvXX8BdWmHI45bWGLViUaS3R/RMrmFSvFMSbJKuEODpM4kR0F0Ofv5SFzCWuNiMhxameWpVdQsnA==} peerDependencies: typescript: '*' @@ -1892,7 +1892,7 @@ packages: minimatch: 9.0.3 muggle-string: 0.3.1 path-browserify: 1.0.1 - typescript: 5.1.6 + typescript: 5.3.3 vue-template-compiler: 2.7.14 dev: true @@ -1930,7 +1930,7 @@ packages: dependencies: '@vue/compiler-ssr': 3.3.11 '@vue/shared': 3.3.11 - vue: 3.3.11(typescript@5.1.6) + vue: 3.3.11(typescript@5.3.3) /@vue/shared@3.3.11: resolution: {integrity: sha512-u2G8ZQ9IhMWTMXaWqZycnK4UthG1fA238CD+DP4Dm4WJi5hdUKKLg0RMRaRpDPNMdkTwIDkp7WtD0Rd9BH9fLw==} @@ -1950,7 +1950,7 @@ packages: dependencies: '@vue/server-renderer': 3.3.11(vue@3.3.11) js-beautify: 1.14.9 - vue: 3.3.11(typescript@5.1.6) + vue: 3.3.11(typescript@5.3.3) vue-component-type-helpers: 1.8.25 dev: true @@ -3464,7 +3464,7 @@ packages: get-stream: 5.2.0 yauzl: 2.10.0 optionalDependencies: - '@types/yauzl': 2.10.0 + '@types/yauzl': 2.10.3 transitivePeerDependencies: - supports-color dev: true @@ -3637,6 +3637,10 @@ packages: resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==} dev: true + /function-bind@1.1.2: + resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} + dev: true + /geckodriver@3.2.0: resolution: {integrity: sha512-p+qR2RKlI/TQoCEYrSuTaYCLqsJNni96WmEukTyXmOmLn+3FLdgPAEwMZ0sG2Cwi9hozUzGAWyT6zLuhF6cpiQ==} engines: {node: '>=12.0.0'} @@ -3885,6 +3889,13 @@ packages: function-bind: 1.1.1 dev: true + /hasown@2.0.0: + resolution: {integrity: sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==} + engines: {node: '>= 0.4'} + dependencies: + function-bind: 1.1.2 + dev: true + /hast-util-from-parse5@8.0.1: resolution: {integrity: sha512-Er/Iixbc7IEa7r/XLtuG52zoqn/b3Xng/w6aZQ0xGVxzhw5xUFxcRqdPzP6yFi/4HBYRaifaI5fQ1RH8n0ZeOQ==} dependencies: @@ -4136,6 +4147,12 @@ packages: has: 1.0.3 dev: true + /is-core-module@2.13.1: + resolution: {integrity: sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==} + dependencies: + hasown: 2.0.0 + dev: true + /is-docker@2.2.1: resolution: {integrity: sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==} engines: {node: '>=8'} @@ -4664,7 +4681,7 @@ packages: jest-pnp-resolver: 1.2.3(jest-resolve@29.7.0) jest-util: 29.7.0 jest-validate: 29.7.0 - resolve: 1.22.4 + resolve: 1.22.8 resolve.exports: 2.0.2 slash: 3.0.0 dev: true @@ -5694,7 +5711,7 @@ packages: resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==} dependencies: hosted-git-info: 2.8.9 - resolve: 1.22.4 + resolve: 1.22.8 semver: 5.7.2 validate-npm-package-license: 3.0.4 dev: true @@ -5704,7 +5721,7 @@ packages: engines: {node: '>=10'} dependencies: hosted-git-info: 4.1.0 - is-core-module: 2.13.0 + is-core-module: 2.13.1 semver: 7.5.4 validate-npm-package-license: 3.0.4 dev: true @@ -6092,6 +6109,11 @@ packages: engines: {node: '>=6'} dev: true + /punycode@2.3.1: + resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} + engines: {node: '>=6'} + dev: true + /pure-rand@6.0.2: resolution: {integrity: sha512-6Yg0ekpKICSjPswYOuC5sku/TSWaRYlA0qsXqJgM/d/4pLPHPuTxK7Nbf7jFKzAeedUhR8C7K9Uv63FBsSo8xQ==} dev: true @@ -6234,7 +6256,7 @@ packages: /resolve@1.19.0: resolution: {integrity: sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==} dependencies: - is-core-module: 2.13.0 + is-core-module: 2.13.1 path-parse: 1.0.7 dev: true @@ -6247,6 +6269,15 @@ packages: supports-preserve-symlinks-flag: 1.0.0 dev: true + /resolve@1.22.8: + resolution: {integrity: sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==} + hasBin: true + dependencies: + is-core-module: 2.13.1 + path-parse: 1.0.7 + supports-preserve-symlinks-flag: 1.0.0 + dev: true + /responselike@2.0.1: resolution: {integrity: sha512-4gl03wn3hj1HP3yzgdI7d3lCkF95F21Pz4BPGvKHinyQzALR5CapwC8yIi0Rh58DEMQ/SguC03wFj2k0M/mHhw==} dependencies: @@ -6305,7 +6336,7 @@ packages: engines: {node: '>=8.0.0'} dev: true - /rollup-plugin-typescript2@0.36.0(rollup@3.29.4)(typescript@5.1.6): + /rollup-plugin-typescript2@0.36.0(rollup@3.29.4)(typescript@5.3.3): resolution: {integrity: sha512-NB2CSQDxSe9+Oe2ahZbf+B4bh7pHwjV5L+RSYpCu7Q5ROuN94F9b6ioWwKfz3ueL3KTtmX4o2MUH2cgHDIEUsw==} peerDependencies: rollup: '>=1.26.3' @@ -6317,7 +6348,7 @@ packages: rollup: 3.29.4 semver: 7.5.4 tslib: 2.6.2 - typescript: 5.1.6 + typescript: 5.3.3 dev: true /rollup@3.29.4: @@ -6928,7 +6959,7 @@ packages: resolution: {integrity: sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==} engines: {node: '>=12'} dependencies: - punycode: 2.3.0 + punycode: 2.3.1 dev: true /trim-lines@3.0.1: @@ -6994,10 +7025,10 @@ packages: typedoc: '>=0.24.0' dependencies: handlebars: 4.7.8 - typedoc: 0.25.4(typescript@5.1.6) + typedoc: 0.25.4(typescript@5.3.3) dev: true - /typedoc@0.25.4(typescript@5.1.6): + /typedoc@0.25.4(typescript@5.3.3): resolution: {integrity: sha512-Du9ImmpBCw54bX275yJrxPVnjdIyJO/84co0/L9mwe0R3G4FSR6rQ09AlXVRvZEGMUg09+z/usc8mgygQ1aidA==} engines: {node: '>= 16'} hasBin: true @@ -7008,7 +7039,7 @@ packages: marked: 4.3.0 minimatch: 9.0.3 shiki: 0.14.3 - typescript: 5.1.6 + typescript: 5.3.3 dev: true /typescript@5.0.4: @@ -7021,6 +7052,12 @@ packages: resolution: {integrity: sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==} engines: {node: '>=14.17'} hasBin: true + dev: false + + /typescript@5.3.3: + resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==} + engines: {node: '>=14.17'} + hasBin: true /uglify-js@3.17.4: resolution: {integrity: sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==} @@ -7105,7 +7142,7 @@ packages: /uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} dependencies: - punycode: 2.3.0 + punycode: 2.3.1 dev: true /url-parse@1.5.10: @@ -7297,16 +7334,16 @@ packages: he: 1.2.0 dev: true - /vue-tsc@1.8.25(typescript@5.1.6): + /vue-tsc@1.8.25(typescript@5.3.3): resolution: {integrity: sha512-lHsRhDc/Y7LINvYhZ3pv4elflFADoEOo67vfClAfF2heVHpHmVquLSjojgCSIwzA4F0Pc4vowT/psXCYcfk+iQ==} hasBin: true peerDependencies: typescript: '*' dependencies: '@volar/typescript': 1.11.1 - '@vue/language-core': 1.8.25(typescript@5.1.6) + '@vue/language-core': 1.8.25(typescript@5.3.3) semver: 7.5.4 - typescript: 5.1.6 + typescript: 5.3.3 dev: true /vue@3.3.11(typescript@5.1.6): @@ -7323,6 +7360,22 @@ packages: '@vue/server-renderer': 3.3.11(vue@3.3.11) '@vue/shared': 3.3.11 typescript: 5.1.6 + dev: false + + /vue@3.3.11(typescript@5.3.3): + resolution: {integrity: sha512-d4oBctG92CRO1cQfVBZp6WJAs0n8AK4Xf5fNjQCBeKCvMI1efGQ5E3Alt1slFJS9fZuPcFoiAiqFvQlv1X7t/w==} + peerDependencies: + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@vue/compiler-dom': 3.3.11 + '@vue/compiler-sfc': 3.3.11 + '@vue/runtime-dom': 3.3.11 + '@vue/server-renderer': 3.3.11(vue@3.3.11) + '@vue/shared': 3.3.11 + typescript: 5.3.3 /w3c-hr-time@1.0.2: resolution: {integrity: sha512-z8P5DvDNjKDoFIHK7q8r8lackT6l+jo/Ye3HOle7l9nICP9lf1Ci25fy9vHd0JOWewkIFzXIEig3TdKT7JQ5fQ==} From 4d93e4e18c8c55a95abbc470994a446fc58cb86f Mon Sep 17 00:00:00 2001 From: quxinyong <41179912+quxinyong@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:32:28 +0800 Subject: [PATCH 009/164] docs(zh): Update navigation-failures.md (#1868) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 应当去掉“还没有”,把文本改为“在当前导航完成之前又有了一个新的导航”。 --- packages/docs/zh/guide/advanced/navigation-failures.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docs/zh/guide/advanced/navigation-failures.md b/packages/docs/zh/guide/advanced/navigation-failures.md index 625780750..c9cb90da7 100644 --- a/packages/docs/zh/guide/advanced/navigation-failures.md +++ b/packages/docs/zh/guide/advanced/navigation-failures.md @@ -67,7 +67,7 @@ if (isNavigationFailure(failure, NavigationFailureType.aborted)) { 正如我们在一开始所说的,有不同的情况会导致导航的中止,所有这些情况都会导致不同的 _Navigation Failure_。它们可以用 `isNavigationFailure` 和 `NavigationFailureType` 来区分。总共有三种不同的类型: - `aborted`:在导航守卫中返回 `false` 中断了本次导航。 -- `cancelled`: 在当前导航还没有完成之前又有了一个新的导航。比如,在等待导航守卫的过程中又调用了 `router.push`。 +- `cancelled`: 在当前导航完成之前又有了一个新的导航。比如,在等待导航守卫的过程中又调用了 `router.push`。 - `duplicated`:导航被阻止,因为我们已经在目标位置了。 ## *导航故障*的属性 From 846e05f46fbe5681660ae08f9dfef095b6f27c63 Mon Sep 17 00:00:00 2001 From: hojas Date: Sat, 16 Dec 2023 11:35:10 +0800 Subject: [PATCH 010/164] docs(zh): remove excess word (#2081) --- packages/docs/zh/guide/advanced/meta.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docs/zh/guide/advanced/meta.md b/packages/docs/zh/guide/advanced/meta.md index 4e1ed64aa..a2a53094b 100644 --- a/packages/docs/zh/guide/advanced/meta.md +++ b/packages/docs/zh/guide/advanced/meta.md @@ -38,7 +38,7 @@ const routes = [ 例如,根据上面的路由配置,`/posts/new` 这个 URL 将会匹配父路由记录 (`path: '/posts'`) 以及子路由记录 (`path: 'new'`)。 -一个路由匹配到的所有路由记录会暴露为 `$route` 对象(还有在导航守卫中的路由对象)的`$route.matched` 数组。我们需要遍历这个数组来检查路由记录中的 `meta` 字段,但是 Vue Router 还为你提供了一个 `$route.meta` 方法,它是一个非递归合并**所有 `meta`** 字段的(从父字段到子字段)的方法。这意味着你可以简单地写 +一个路由匹配到的所有路由记录会暴露为 `$route` 对象(还有在导航守卫中的路由对象)的`$route.matched` 数组。我们需要遍历这个数组来检查路由记录中的 `meta` 字段,但是 Vue Router 还为你提供了一个 `$route.meta` 方法,它是一个非递归合并**所有 `meta`** 字段(从父字段到子字段)的方法。这意味着你可以简单地写 ```js router.beforeEach((to, from) => { From 35a9c1b29d1fed1ac4d09a9640fc0507459c7145 Mon Sep 17 00:00:00 2001 From: freemedom <57294686+freemedom@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:51:11 +0800 Subject: [PATCH 011/164] docs(zh): Update route-matching-syntax.md and navigation-guards.md (#1758) * Update route-matching-syntax.md * Update navigation-guards.md * Update navigation-guards.md * Update navigation-guards.md * Update navigation-guards.md * Apply suggestions from code review --------- Co-authored-by: Jinjiang --- packages/docs/zh/guide/advanced/navigation-guards.md | 4 ++-- packages/docs/zh/guide/essentials/route-matching-syntax.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/docs/zh/guide/advanced/navigation-guards.md b/packages/docs/zh/guide/advanced/navigation-guards.md index 7767b38ca..3f56595d2 100644 --- a/packages/docs/zh/guide/advanced/navigation-guards.md +++ b/packages/docs/zh/guide/advanced/navigation-guards.md @@ -31,7 +31,7 @@ router.beforeEach((to, from) => { 可以返回的值如下: - `false`: 取消当前的导航。如果浏览器的 URL 改变了(可能是用户手动或者浏览器后退按钮),那么 URL 地址会重置到 `from` 路由对应的地址。 -- 一个[路由地址](../../api/#routelocationraw): 通过一个路由地址跳转到一个不同的地址,就像你调用 [`router.push()`](../../api/#push) 一样,你可以设置诸如 `replace: true` 或 `name: 'home'` 之类的配置。当前的导航被中断,然后进行一个新的导航,就和 `from` 一样。 +- 一个[路由地址](../../api/#routelocationraw): 通过一个路由地址重定向到一个不同的地址,如同调用 [`router.push()`](../../api/#push),且可以传入诸如 `replace: true` 或 `name: 'home'` 之类的选项。它会中断当前的导航,同时用相同的 `from` 创建一个新导航。 ```js router.beforeEach(async (to, from) => { @@ -63,7 +63,7 @@ router.beforeEach(async (to, from) => { ### 可选的第三个参数 `next` -在之前的 Vue Router 版本中,也是可以使用 _第三个参数_ `next` 的。这是一个常见的错误来源,可以通过 [RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0037-router-return-guards.md#motivation) 来消除错误。然而,它仍然是被支持的,这意味着你可以向任何导航守卫传递第三个参数。在这种情况下,**确保 `next`** 在任何给定的导航守卫中都被**严格调用一次**。它可以出现多于一次,但是只能在所有的逻辑路径都不重叠的情况下,否则钩子永远都不会被解析或报错。这里有一个在用户未能验证身份时重定向到`/login`的**错误用例**: +在之前的 Vue Router 版本中,还可以使用 _第三个参数_ `next` 。这是一个常见的错误来源,我们经过 [RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0037-router-return-guards.md#motivation) 讨论将其移除。然而,它仍然是被支持的,这意味着你可以向任何导航守卫传递第三个参数。在这种情况下,**确保 `next`** 在任何给定的导航守卫中都被**严格调用一次**。它可以出现多于一次,但是只能在所有的逻辑路径都不重叠的情况下,否则钩子永远都不会被解析或报错。这里有一个在用户未能验证身份时重定向到`/login`的**错误用例**: ```js // BAD diff --git a/packages/docs/zh/guide/essentials/route-matching-syntax.md b/packages/docs/zh/guide/essentials/route-matching-syntax.md index 1df1e106e..372ed674a 100644 --- a/packages/docs/zh/guide/essentials/route-matching-syntax.md +++ b/packages/docs/zh/guide/essentials/route-matching-syntax.md @@ -13,7 +13,7 @@ ## 在参数中自定义正则 -当定义像 `:userId` 这样的参数时,我们内部使用以下的正则 `([^/]+)` (至少有一个字符不是斜杠 `/` )来从 URL 中提取参数。这很好用,除非你需要根据参数的内容来区分两个路由。想象一下,两个路由 `/:orderId` 和 `/:productName`,两者会匹配完全相同的 URL,所以我们需要一种方法来区分它们。最简单的方法就是在路径中添加一个静态部分来区分它们: +当定义像 `:userId` 这样的参数时,我们内部使用以下的正则 `([^/]+)` (至少一个不是斜杠 `/` 的字符)来从 URL 中提取参数。这很好用,除非你需要根据参数的内容来区分两个路由。想象一下,两个路由 `/:orderId` 和 `/:productName`,两者会匹配完全相同的 URL,所以我们需要一种方法来区分它们。最简单的方法就是在路径中添加一个静态部分来区分它们: ```js const routes = [ From 110c86929ac92e2428d8d4958b6c6374754bc0df Mon Sep 17 00:00:00 2001 From: Jinjiang Date: Thu, 21 Dec 2023 00:44:44 +0800 Subject: [PATCH 012/164] docs(zh): sync update to 35a9c1b (#2084) --- packages/docs/.vitepress/config/zh.ts | 8 + .../docs/.vitepress/translation-status.json | 6 +- packages/docs/zh/api/index.md | 92 +++++---- .../docs/zh/api/interfaces/NavigationGuard.md | 8 +- .../api/interfaces/NavigationGuardWithThis.md | 10 +- .../zh/api/interfaces/RouteLocationMatched.md | 28 ++- .../api/interfaces/RouteLocationNormalized.md | 2 +- packages/docs/zh/api/interfaces/RouteMeta.md | 2 +- .../docs/zh/api/interfaces/RouteRecordBase.md | 151 ++++++++++++++ .../interfaces/RouteRecordMultipleViews.md | 189 ++++++++++++++++++ .../RouteRecordMultipleViewsWithChildren.md | 189 ++++++++++++++++++ .../api/interfaces/RouteRecordNormalized.md | 30 ++- .../zh/api/interfaces/RouteRecordRedirect.md | 186 +++++++++++++++++ .../api/interfaces/RouteRecordSingleView.md | 187 +++++++++++++++++ .../RouteRecordSingleViewWithChildren.md | 187 +++++++++++++++++ packages/docs/zh/api/interfaces/Router.md | 40 ++-- .../docs/zh/api/interfaces/RouterHistory.md | 16 +- .../docs/zh/api/interfaces/RouterOptions.md | 22 +- .../zh/api/interfaces/RouterScrollBehavior.md | 8 +- .../docs/zh/guide/advanced/dynamic-routing.md | 2 +- .../docs/zh/guide/advanced/lazy-loading.md | 6 +- packages/docs/zh/guide/advanced/meta.md | 15 +- .../zh/guide/advanced/navigation-failures.md | 14 ++ .../zh/guide/advanced/navigation-guards.md | 26 ++- .../zh/guide/advanced/router-view-slot.md | 75 +++++++ .../docs/zh/guide/advanced/scroll-behavior.md | 3 +- .../docs/zh/guide/advanced/transitions.md | 8 +- .../docs/zh/guide/essentials/history-mode.md | 20 +- .../docs/zh/guide/essentials/named-routes.md | 6 +- .../docs/zh/guide/essentials/named-views.md | 4 +- .../docs/zh/guide/essentials/navigation.md | 10 +- .../docs/zh/guide/essentials/passing-props.md | 19 ++ packages/docs/zh/guide/index.md | 2 +- packages/docs/zh/guide/migration/index.md | 15 ++ packages/docs/zh/installation.md | 46 ++++- 35 files changed, 1483 insertions(+), 149 deletions(-) create mode 100644 packages/docs/zh/api/interfaces/RouteRecordBase.md create mode 100644 packages/docs/zh/api/interfaces/RouteRecordMultipleViews.md create mode 100644 packages/docs/zh/api/interfaces/RouteRecordMultipleViewsWithChildren.md create mode 100644 packages/docs/zh/api/interfaces/RouteRecordRedirect.md create mode 100644 packages/docs/zh/api/interfaces/RouteRecordSingleView.md create mode 100644 packages/docs/zh/api/interfaces/RouteRecordSingleViewWithChildren.md create mode 100644 packages/docs/zh/guide/advanced/router-view-slot.md diff --git a/packages/docs/.vitepress/config/zh.ts b/packages/docs/.vitepress/config/zh.ts index 0776b6666..83068e02a 100644 --- a/packages/docs/.vitepress/config/zh.ts +++ b/packages/docs/.vitepress/config/zh.ts @@ -48,6 +48,10 @@ export const zhConfig: LocaleSpecificConfig = { text: '更新日志', link: 'https://github.com/vuejs/router/blob/main/packages/router/CHANGELOG.md', }, + { + text: 'Vue.js 认证', + link: 'https://certification.vuejs.org/?friend=VUEROUTER', + }, ], }, ], @@ -139,6 +143,10 @@ export const zhConfig: LocaleSpecificConfig = { text: '组合式 API', link: '/zh/guide/advanced/composition-api.html', }, + { + text: 'RouterView 插槽', + link: '/guide/advanced/router-view-slot.html', + }, { text: '过渡动效', link: '/zh/guide/advanced/transitions.html', diff --git a/packages/docs/.vitepress/translation-status.json b/packages/docs/.vitepress/translation-status.json index 1a2101278..ea46a9127 100644 --- a/packages/docs/.vitepress/translation-status.json +++ b/packages/docs/.vitepress/translation-status.json @@ -1,6 +1,6 @@ { "zh": { - "hash": "1a3a28f", - "date": "2023-04-08" + "hash": "35a9c1b", + "date": "2023-12-16" } -} +} \ No newline at end of file diff --git a/packages/docs/zh/api/index.md b/packages/docs/zh/api/index.md index 63efd7c2a..3d1183ae4 100644 --- a/packages/docs/zh/api/index.md +++ b/packages/docs/zh/api/index.md @@ -20,19 +20,25 @@ API 文档 - [RouteLocationNormalizedLoaded](interfaces/RouteLocationNormalizedLoaded.md) - [RouteLocationOptions](interfaces/RouteLocationOptions.md) - [RouteMeta](interfaces/RouteMeta.md) +- [RouteRecordMultipleViews](interfaces/RouteRecordMultipleViews.md) +- [RouteRecordMultipleViewsWithChildren](interfaces/RouteRecordMultipleViewsWithChildren.md) - [RouteRecordNormalized](interfaces/RouteRecordNormalized.md) +- [RouteRecordRedirect](interfaces/RouteRecordRedirect.md) +- [RouteRecordSingleView](interfaces/RouteRecordSingleView.md) +- [RouteRecordSingleViewWithChildren](interfaces/RouteRecordSingleViewWithChildren.md) - [Router](interfaces/Router.md) - [RouterHistory](interfaces/RouterHistory.md) - [RouterLinkProps](interfaces/RouterLinkProps.md) - [RouterOptions](interfaces/RouterOptions.md) - [RouterScrollBehavior](interfaces/RouterScrollBehavior.md) - [RouterViewProps](interfaces/RouterViewProps.md) +- [\_RouteRecordBase](interfaces/RouteRecordBase.md) ## TS 类型别名 %{#Type-Aliases}% ### LocationQuery %{#Type-Aliases-LocationQuery}% -Ƭ **LocationQuery**: `Record`<`string`, `LocationQueryValue` \| `LocationQueryValue`[]\> +Ƭ **LocationQuery**: `Record`\<`string`, `LocationQueryValue` \| `LocationQueryValue`[]\> 出现在 [RouteLocationNormalized](interfaces/RouteLocationNormalized.md) 中的规范化查询对象。 @@ -40,17 +46,17 @@ ___ ### LocationQueryRaw %{#Type-Aliases-LocationQueryRaw}% -Ƭ **LocationQueryRaw**: `Record`<`string` \| `number`, `LocationQueryValueRaw` \| `LocationQueryValueRaw`[]\> +Ƭ **LocationQueryRaw**: `Record`\<`string` \| `number`, `LocationQueryValueRaw` \| `LocationQueryValueRaw`[]\> 松散的 [LocationQuery](index.md#locationquery) 对象,可以被传递给诸如 -[push](interfaces/Router.md#push)、[replace](interfaces/Router.md#replace) 或任何创建 +[Router.push](interfaces/Router.md#push)、[Router.replace](interfaces/Router.md#replace) 或任何创建 [RouteLocationRaw](index.md#routelocationraw) 的函数。 ___ ### PathParserOptions %{#Type-Aliases-PathParserOptions}% -Ƭ **PathParserOptions**: `Pick`<`_PathParserOptions`, ``"end"`` \| ``"sensitive"`` \| ``"strict"``\> +Ƭ **PathParserOptions**: `Pick`\<`_PathParserOptions`, ``"end"`` \| ``"sensitive"`` \| ``"strict"``\> ___ @@ -72,13 +78,13 @@ ___ ### RouteParams %{#Type-Aliases-RouteParams}% -Ƭ **RouteParams**: `Record`<`string`, `RouteParamValue` \| `RouteParamValue`[]\> +Ƭ **RouteParams**: `Record`\<`string`, `RouteParamValue` \| `RouteParamValue`[]\> ___ ### RouteParamsRaw %{#Type-Aliases-RouteParamsRaw}% -Ƭ **RouteParamsRaw**: `Record`<`string`, `RouteParamValueRaw` \| `Exclude`<`RouteParamValueRaw`, ``null`` \| `undefined`\>[]\> +Ƭ **RouteParamsRaw**: `Record`\<`string`, `RouteParamValueRaw` \| `Exclude`\<`RouteParamValueRaw`, ``null`` \| `undefined`\>[]\> ___ @@ -100,13 +106,13 @@ ___ ### RouteRecordRaw %{#Type-Aliases-RouteRecordRaw}% -Ƭ **RouteRecordRaw**: `RouteRecordSingleView` \| `RouteRecordSingleViewWithChildren` \| `RouteRecordMultipleViews` \| `RouteRecordMultipleViewsWithChildren` \| `RouteRecordRedirect` +Ƭ **RouteRecordRaw**: [`RouteRecordSingleView`](interfaces/RouteRecordSingleView.md) \| [`RouteRecordSingleViewWithChildren`](interfaces/RouteRecordSingleViewWithChildren.md) \| [`RouteRecordMultipleViews`](interfaces/RouteRecordMultipleViews.md) \| [`RouteRecordMultipleViewsWithChildren`](interfaces/RouteRecordMultipleViewsWithChildren.md) \| [`RouteRecordRedirect`](interfaces/RouteRecordRedirect.md) ___ ### UseLinkOptions %{#Type-Aliases-UseLinkOptions}% -Ƭ **UseLinkOptions**: `VueUseOptions`<`RouterLinkOptions`\> +Ƭ **UseLinkOptions**: `VueUseOptions`\<`RouterLinkOptions`\> ## 变量 %{#Variables}% @@ -120,14 +126,24 @@ ___ ### RouterView %{#Variables-RouterView}% -• `Const` **RouterView**: () => { `$props`: `AllowedComponentProps` & `ComponentCustomProps` & `VNodeProps` & [`RouterViewProps`](interfaces/RouterViewProps.md) ; `$slots`: { `default?`: (`__namedParameters`: { `Component`: `VNode`<`RendererNode`, `RendererElement`, { `[key: string]`: `any`; }\> ; `route`: [`RouteLocationNormalizedLoaded`](interfaces/RouteLocationNormalizedLoaded.md) }) => `VNode`<`RendererNode`, `RendererElement`, { `[key: string]`: `any`; }\>[] } } +• `Const` **RouterView**: () => \{ `$props`: `AllowedComponentProps` & `ComponentCustomProps` & `VNodeProps` & [`RouterViewProps`](interfaces/RouterViewProps.md) ; `$slots`: \{ `default?`: (`__namedParameters`: \{ `Component`: `VNode`\<`RendererNode`, `RendererElement`, \{ `[key: string]`: `any`; }\> ; `route`: [`RouteLocationNormalizedLoaded`](interfaces/RouteLocationNormalizedLoaded.md) }) => `VNode`\<`RendererNode`, `RendererElement`, \{ `[key: string]`: `any`; }\>[] } } #### 类型声明 %{#Variables-RouterView-Type-declaration}% -• **new RouterView**() +• **new RouterView**(): `Object` 用于显示用户当前所处路由的组件。 +##### 返回值 %{#Variables-RouterView-Returns}% + +`Object` + +| 名称 | 类型 | +| :------ | :------ | +| `$props` | `AllowedComponentProps` & `ComponentCustomProps` & `VNodeProps` & [`RouterViewProps`](interfaces/RouterViewProps.md) | +| `$slots` | \{ `default?`: (`__namedParameters`: \{ `Component`: `VNode`\<`RendererNode`, `RendererElement`, \{ `[key: string]`: `any`; }\> ; `route`: [`RouteLocationNormalizedLoaded`](interfaces/RouteLocationNormalizedLoaded.md) }) => `VNode`\<`RendererNode`, `RendererElement`, \{ `[key: string]`: `any`; }\>[] } | +| `$slots.default?` | (`__namedParameters`: \{ `Component`: `VNode`\<`RendererNode`, `RendererElement`, \{ `[key: string]`: `any`; }\> ; `route`: [`RouteLocationNormalizedLoaded`](interfaces/RouteLocationNormalizedLoaded.md) }) => `VNode`\<`RendererNode`, `RendererElement`, \{ `[key: string]`: `any`; }\>[] | + ___ ### START\_LOCATION %{#Variables-START_LOCATION}% @@ -194,6 +210,16 @@ ___ 创建一个 hash 模式的历史。在没有主机的 web 应用 (如 `file://`) 或无法通过配置服务器来处理任意 URL 的时候非常有用。 +#### 参数 %{#Functions-createWebHashHistory-Parameters}% + +| 名称 | 类型 | 描述 | +| :------ | :------ | :------ | +| `base?` | `string` | 可选提供的基础位置。默认为 `location.pathname + location.search`。如果在 `head` 中有一个 `` 标签,它的值会因此被忽略,**但注意它会影响所有 history.pushState() 的调用**,这意味着如果你使用一个 `` 标签,它的 `href` 值**必须与这个参数匹配** (忽略 `#` 后的任何东西)。 | + +#### 返回值 %{#Functions-createWebHashHistory-Returns}% + +[`RouterHistory`](interfaces/RouterHistory.md) + **示例** ```js @@ -210,16 +236,6 @@ createWebHashHistory('/other-folder/') // 给出一个 `https://example.com/othe createWebHashHistory('/iAmIgnored') // 给出一个 `file:///usr/etc/folder/index.html#` 的 URL ``` -#### 参数 %{#Functions-createWebHashHistory-Parameters}% - -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `base?` | `string` | 可选提供的基础位置。默认为 `location.pathname + location.search`。如果在 `head` 中有一个 `` 标签,它的值会因此被忽略,**但注意它会影响所有 history.pushState() 的调用**,这意味着如果你使用一个 `` 标签,它的 `href` 值**必须与这个参数匹配** (忽略 `#` 后的任何东西)。 | - -#### 返回值 %{#Functions-createWebHashHistory-Returns}% - -[`RouterHistory`](interfaces/RouterHistory.md) - ___ ### createWebHistory %{#Functions-createWebHistory}% @@ -246,6 +262,17 @@ ___ 检查一个对象是否是 [NavigationFailure](interfaces/NavigationFailure.md)。 +#### 参数 %{#Functions-isNavigationFailure-Parameters}% + +| 名称 | 类型 | 描述 | +| :------ | :------ | :------ | +| `error` | `any` | 可能的 [NavigationFailure](interfaces/NavigationFailure.md) | +| `type?` | `NAVIGATION_GUARD_REDIRECT` | 可选的待检查类型 | + +#### 返回值 %{#Functions-isNavigationFailure-Returns}% + +error is NavigationRedirectError + **示例** ```js @@ -267,17 +294,6 @@ router.afterEach((to, from, failure) => { }) ``` -#### 参数 %{#Functions-isNavigationFailure-Parameters}% - -| 名称 | 类型 | 描述 | -| :------ | :------ | :------ | -| `error` | `any` | 可能的 [NavigationFailure](interfaces/NavigationFailure.md) | -| `type?` | `NAVIGATION_GUARD_REDIRECT` | 可选的待检查类型 | - -#### 返回值 %{#Functions-isNavigationFailure-Returns}% - -error is NavigationRedirectError - ▸ **isNavigationFailure**(`error`, `type?`): error is NavigationFailure #### 参数 %{#Functions-isNavigationFailure-Parameters_1}% @@ -295,7 +311,7 @@ ___ ### loadRouteLocation %{#Functions-loadRouteLocation}% -▸ **loadRouteLocation**(`route`): `Promise`<[`RouteLocationNormalizedLoaded`](interfaces/RouteLocationNormalizedLoaded.md)\> +▸ **loadRouteLocation**(`route`): `Promise`\<[`RouteLocationNormalizedLoaded`](interfaces/RouteLocationNormalizedLoaded.md)\> 确保路由被加载,所以它可以作为一个 prop 传递给 ``。 @@ -307,7 +323,7 @@ ___ #### 返回值 %{#Functions-loadRouteLocation-Returns}% -`Promise`<[`RouteLocationNormalizedLoaded`](interfaces/RouteLocationNormalizedLoaded.md)\> +`Promise`\<[`RouteLocationNormalizedLoaded`](interfaces/RouteLocationNormalizedLoaded.md)\> ___ @@ -355,7 +371,7 @@ ___ | 名称 | 类型 | | :------ | :------ | -| `props` | `VueUseOptions`<`RouterLinkOptions`\> | +| `props` | `VueUseOptions`\<`RouterLinkOptions`\> | #### 返回值 %{#Functions-useLink-Returns}% @@ -364,10 +380,10 @@ ___ | 名称 | 类型 | | :------ | :------ | | `href` | `ComputedRef` | -| `isActive` | `ComputedRef`<`boolean`\> | -| `isExactActive` | `ComputedRef`<`boolean`\> | -| `navigate` | (`e`: `MouseEvent`) => `Promise`<`void` \| [`NavigationFailure`](interfaces/NavigationFailure.md)\> | -| `route` | `ComputedRef`<[`RouteLocation`](interfaces/RouteLocation.md) & { `href`: `string` }\> | +| `isActive` | `ComputedRef`\<`boolean`\> | +| `isExactActive` | `ComputedRef`\<`boolean`\> | +| `navigate` | (`e`: `MouseEvent`) => `Promise`\<`void` \| [`NavigationFailure`](interfaces/NavigationFailure.md)\> | +| `route` | `ComputedRef`\<[`RouteLocation`](interfaces/RouteLocation.md) & { `href`: `string` }\> | ___ diff --git a/packages/docs/zh/api/interfaces/NavigationGuard.md b/packages/docs/zh/api/interfaces/NavigationGuard.md index 10c1d0aef..52a86b69b 100644 --- a/packages/docs/zh/api/interfaces/NavigationGuard.md +++ b/packages/docs/zh/api/interfaces/NavigationGuard.md @@ -6,13 +6,13 @@ editLink: false # 接口:NavigationGuard %{#interface-navigationguard}% +导航守卫。详情可查阅[导航守卫](/zh/guide/advanced/navigation-guards.md)。 + ## 可调用函数 %{#Callable}% ### NavigationGuard %{#Callable-NavigationGuard}% -▸ **NavigationGuard**(`to`, `from`, `next`): `NavigationGuardReturn` \| `Promise`<`NavigationGuardReturn`\> - -导航守卫。详情可查阅[导航守卫](/zh/guide/advanced/navigation-guards.md). +▸ **NavigationGuard**(`to`, `from`, `next`): `NavigationGuardReturn` \| `Promise`\<`NavigationGuardReturn`\> #### 参数 %{#Callable-NavigationGuard-Parameters}% @@ -24,4 +24,4 @@ editLink: false #### 返回值 %{#Callable-NavigationGuard-Returns}% -`NavigationGuardReturn` \| `Promise`<`NavigationGuardReturn`\> +`NavigationGuardReturn` \| `Promise`\<`NavigationGuardReturn`\> diff --git a/packages/docs/zh/api/interfaces/NavigationGuardWithThis.md b/packages/docs/zh/api/interfaces/NavigationGuardWithThis.md index dc89efa70..1a82c2d65 100644 --- a/packages/docs/zh/api/interfaces/NavigationGuardWithThis.md +++ b/packages/docs/zh/api/interfaces/NavigationGuardWithThis.md @@ -4,7 +4,9 @@ editLink: false [API 参考](../index.md) / NavigationGuardWithThis -# 接口:NavigationGuardWithThis %{#interface-navigationguardwiththis-t}% +# 接口:NavigationGuardWithThis\ %{#interface-navigationguardwiththis-t}% + +导航守卫。详情可查阅[导航守卫](/zh/guide/advanced/navigation-guards.md)。 ## 类型参数 %{#Type-parameters}% @@ -16,9 +18,7 @@ editLink: false ### NavigationGuardWithThis %{#Callable-NavigationGuardWithThis}% -▸ **NavigationGuardWithThis**(`this`, `to`, `from`, `next`): `NavigationGuardReturn` \| `Promise`<`NavigationGuardReturn`\> - -导航守卫。详情可查阅[导航守卫](/zh/guide/advanced/navigation-guards.md). +▸ **NavigationGuardWithThis**(`this`, `to`, `from`, `next`): `NavigationGuardReturn` \| `Promise`\<`NavigationGuardReturn`\> #### 参数 %{#Callable-NavigationGuardWithThis-Parameters}% @@ -31,4 +31,4 @@ editLink: false #### 返回值 %{#Callable-NavigationGuardWithThis-Returns}% -`NavigationGuardReturn` \| `Promise`<`NavigationGuardReturn`\> +`NavigationGuardReturn` \| `Promise`\<`NavigationGuardReturn`\> diff --git a/packages/docs/zh/api/interfaces/RouteLocationMatched.md b/packages/docs/zh/api/interfaces/RouteLocationMatched.md index 3b8d08984..ea52970a1 100644 --- a/packages/docs/zh/api/interfaces/RouteLocationMatched.md +++ b/packages/docs/zh/api/interfaces/RouteLocationMatched.md @@ -30,7 +30,7 @@ ___ ### beforeEnter %{#Properties-beforeEnter}% -• **beforeEnter**: `undefined` \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)<`undefined`\> \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)<`undefined`\>[] +• **beforeEnter**: `undefined` \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\> \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\>[] 被注册的 beforeEnter 守卫 @@ -54,7 +54,7 @@ ___ ### components %{#Properties-components}% -• **components**: `undefined` \| ``null`` \| `Record`<`string`, [`RouteComponent`](../index.md#routecomponent)\> +• **components**: `undefined` \| ``null`` \| `Record`\<`string`, [`RouteComponent`](../index.md#routecomponent)\> {@inheritDoc RouteRecordMultipleViews.components} @@ -66,7 +66,7 @@ ___ ### instances %{#Properties-instances}% -• **instances**: `Record`<`string`, `undefined` \| ``null`` \| `ComponentPublicInstance`<{}, {}, {}, {}, {}, {}, {}, {}, ``false``, `ComponentOptionsBase`<`any`, `any`, `any`, `any`, `any`, `any`, `any`, `any`, `any`, {}, {}, `string`\>, {}\>\> +• **instances**: `Record`\<`string`, `undefined` \| ``null`` \| `ComponentPublicInstance`\> @@ -82,7 +82,9 @@ ___ • **meta**: [`RouteMeta`](RouteMeta.md) -{@inheritDoc _RouteRecordBase.meta} + + +Arbitrary data attached to the record. #### 继承自 %{#Properties-meta-Inherited-from}% @@ -94,7 +96,9 @@ ___ • **name**: `undefined` \| [`RouteRecordName`](../index.md#routerecordname) -{@inheritDoc _RouteRecordBase.name} + + +Name for the route record. Must be unique. #### 继承自 %{#Properties-name-Inherited-from}% @@ -106,7 +110,9 @@ ___ • **path**: `string` -{@inheritDoc _RouteRecordBase.path} + + +Path of the record. Should start with `/` unless the record is the child of another record. #### 继承自 %{#Properties-path-Inherited-from}% @@ -116,9 +122,11 @@ ___ ### props %{#Properties-props}% -• **props**: `Record`<`string`, `_RouteRecordProps`\> +• **props**: `Record`\<`string`, `_RouteRecordProps`\> + + -{@inheritDoc RouteRecordMultipleViews.props} +Allow passing down params as props to the component rendered by `router-view`. Should be an object with the same keys as `components` or a boolean to be applied to every component. #### 继承自 %{#Properties-props-Inherited-from}% @@ -130,7 +138,9 @@ ___ • **redirect**: `undefined` \| `RouteRecordRedirectOption` -{@inheritDoc _RouteRecordBase.redirect} + + +Where to redirect if the route is directly matched. The redirection happens before any navigation guard and triggers a new navigation with the new target location. #### 继承自 %{#Properties-redirect-Inherited-from}% diff --git a/packages/docs/zh/api/interfaces/RouteLocationNormalized.md b/packages/docs/zh/api/interfaces/RouteLocationNormalized.md index 820dc7e50..b0ae66d64 100644 --- a/packages/docs/zh/api/interfaces/RouteLocationNormalized.md +++ b/packages/docs/zh/api/interfaces/RouteLocationNormalized.md @@ -6,7 +6,7 @@ editLink: false # 接口:RouteLocationNormalized -和 [RouteLocation](RouteLocation.md) 类似但是其 [matched](RouteLocationNormalized.md#matched) 无法包含重定向的记录 +和 [RouteLocation](RouteLocation.md) 类似但是其 [RouteLocationNormalized.matched](RouteLocationNormalized.md#matched) 无法包含重定向的记录 ## 继承关系 %{#Hierarchy}% diff --git a/packages/docs/zh/api/interfaces/RouteMeta.md b/packages/docs/zh/api/interfaces/RouteMeta.md index d7fdb4c09..0e3ad6132 100644 --- a/packages/docs/zh/api/interfaces/RouteMeta.md +++ b/packages/docs/zh/api/interfaces/RouteMeta.md @@ -23,6 +23,6 @@ declare module 'vue-router' { ## 继承关系 %{#Hierarchy}% -- `Record`<`string` \| `number` \| `symbol`, `unknown`\> +- `Record`\<`string` \| `number` \| `symbol`, `unknown`\> ↳ **`RouteMeta`** diff --git a/packages/docs/zh/api/interfaces/RouteRecordBase.md b/packages/docs/zh/api/interfaces/RouteRecordBase.md new file mode 100644 index 000000000..0958b0d10 --- /dev/null +++ b/packages/docs/zh/api/interfaces/RouteRecordBase.md @@ -0,0 +1,151 @@ +--- +editLink: false +--- + + + +[API Documentation](../index.md) / \_RouteRecordBase + +# Interface: \_RouteRecordBase + +Internal type for common properties among all kind of [RouteRecordRaw](../index.md#RouteRecordRaw). + +## Hierarchy + +- [`PathParserOptions`](../index.md#PathParserOptions) + + ↳ **`_RouteRecordBase`** + + ↳↳ [`RouteRecordSingleView`](RouteRecordSingleView.md) + + ↳↳ [`RouteRecordSingleViewWithChildren`](RouteRecordSingleViewWithChildren.md) + + ↳↳ [`RouteRecordMultipleViews`](RouteRecordMultipleViews.md) + + ↳↳ [`RouteRecordMultipleViewsWithChildren`](RouteRecordMultipleViewsWithChildren.md) + + ↳↳ [`RouteRecordRedirect`](RouteRecordRedirect.md) + +## Properties + +### alias + +• `Optional` **alias**: `string` \| `string`[] + +Aliases for the record. Allows defining extra paths that will behave like a +copy of the record. Allows having paths shorthands like `/users/:id` and +`/u/:id`. All `alias` and `path` values must share the same params. + +___ + +### beforeEnter + +• `Optional` **beforeEnter**: [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\> \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\>[] + +Before Enter guard specific to this record. Note `beforeEnter` has no +effect if the record has a `redirect` property. + +___ + +### children + +• `Optional` **children**: [`RouteRecordRaw`](../index.md#RouteRecordRaw)[] + +Array of nested routes. + +___ + +### end + +• `Optional` **end**: `boolean` + +Should the RegExp match until the end by appending a `$` to it. + +**`Default Value`** + +`true` + +#### Inherited from + +PathParserOptions.end + +___ + +### meta + +• `Optional` **meta**: [`RouteMeta`](RouteMeta.md) + +Arbitrary data attached to the record. + +___ + +### name + +• `Optional` **name**: [`RouteRecordName`](../index.md#RouteRecordName) + +Name for the route record. Must be unique. + +___ + +### path + +• **path**: `string` + +Path of the record. Should start with `/` unless the record is the child of +another record. + +**`Example`** + +```ts +`/users/:id` matches `/users/1` as well as `/users/posva`. +``` + +___ + +### props + +• `Optional` **props**: `_RouteRecordProps` \| `Record`\<`string`, `_RouteRecordProps`\> + +Allow passing down params as props to the component rendered by `router-view`. + +___ + +### redirect + +• `Optional` **redirect**: `RouteRecordRedirectOption` + +Where to redirect if the route is directly matched. The redirection happens +before any navigation guard and triggers a new navigation with the new +target location. + +___ + +### sensitive + +• `Optional` **sensitive**: `boolean` + +Makes the RegExp case-sensitive. + +**`Default Value`** + +`false` + +#### Inherited from + +PathParserOptions.sensitive + +___ + +### strict + +• `Optional` **strict**: `boolean` + +Whether to disallow a trailing slash or not. + +**`Default Value`** + +`false` + +#### Inherited from + +PathParserOptions.strict diff --git a/packages/docs/zh/api/interfaces/RouteRecordMultipleViews.md b/packages/docs/zh/api/interfaces/RouteRecordMultipleViews.md new file mode 100644 index 000000000..c18ffd146 --- /dev/null +++ b/packages/docs/zh/api/interfaces/RouteRecordMultipleViews.md @@ -0,0 +1,189 @@ +--- +editLink: false +--- + + + +[API Documentation](../index.md) / RouteRecordMultipleViews + +# Interface: RouteRecordMultipleViews + +Route Record defining multiple named components with the `components` option. + +## Hierarchy + +- [`_RouteRecordBase`](RouteRecordBase.md) + + ↳ **`RouteRecordMultipleViews`** + +## Properties + +### alias + +• `Optional` **alias**: `string` \| `string`[] + +Aliases for the record. Allows defining extra paths that will behave like a +copy of the record. Allows having paths shorthands like `/users/:id` and +`/u/:id`. All `alias` and `path` values must share the same params. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[alias](RouteRecordBase.md#alias) + +___ + +### beforeEnter + +• `Optional` **beforeEnter**: [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\> \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\>[] + +Before Enter guard specific to this record. Note `beforeEnter` has no +effect if the record has a `redirect` property. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[beforeEnter](RouteRecordBase.md#beforeEnter) + +___ + +### children + +• `Optional` **children**: `undefined` + +Array of nested routes. + +#### Overrides + +[_RouteRecordBase](RouteRecordBase.md).[children](RouteRecordBase.md#children) + +___ + +### component + +• `Optional` **component**: `undefined` + +___ + +### components + +• **components**: `Record`\<`string`, `RawRouteComponent`\> + +Components to display when the URL matches this route. Allow using named views. + +___ + +### end + +• `Optional` **end**: `boolean` + +Should the RegExp match until the end by appending a `$` to it. + +**`Default Value`** + +`true` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[end](RouteRecordBase.md#end) + +___ + +### meta + +• `Optional` **meta**: [`RouteMeta`](RouteMeta.md) + +Arbitrary data attached to the record. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[meta](RouteRecordBase.md#meta) + +___ + +### name + +• `Optional` **name**: [`RouteRecordName`](../index.md#RouteRecordName) + +Name for the route record. Must be unique. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[name](RouteRecordBase.md#name) + +___ + +### path + +• **path**: `string` + +Path of the record. Should start with `/` unless the record is the child of +another record. + +**`Example`** + +```ts +`/users/:id` matches `/users/1` as well as `/users/posva`. +``` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[path](RouteRecordBase.md#path) + +___ + +### props + +• `Optional` **props**: `boolean` \| `Record`\<`string`, `_RouteRecordProps`\> + +Allow passing down params as props to the component rendered by +`router-view`. Should be an object with the same keys as `components` or a +boolean to be applied to every component. + +#### Overrides + +[_RouteRecordBase](RouteRecordBase.md).[props](RouteRecordBase.md#props) + +___ + +### redirect + +• `Optional` **redirect**: `undefined` + +Where to redirect if the route is directly matched. The redirection happens +before any navigation guard and triggers a new navigation with the new +target location. + +#### Overrides + +[_RouteRecordBase](RouteRecordBase.md).[redirect](RouteRecordBase.md#redirect) + +___ + +### sensitive + +• `Optional` **sensitive**: `boolean` + +Makes the RegExp case-sensitive. + +**`Default Value`** + +`false` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[sensitive](RouteRecordBase.md#sensitive) + +___ + +### strict + +• `Optional` **strict**: `boolean` + +Whether to disallow a trailing slash or not. + +**`Default Value`** + +`false` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[strict](RouteRecordBase.md#strict) diff --git a/packages/docs/zh/api/interfaces/RouteRecordMultipleViewsWithChildren.md b/packages/docs/zh/api/interfaces/RouteRecordMultipleViewsWithChildren.md new file mode 100644 index 000000000..6c0a464cb --- /dev/null +++ b/packages/docs/zh/api/interfaces/RouteRecordMultipleViewsWithChildren.md @@ -0,0 +1,189 @@ +--- +editLink: false +--- + + + +[API Documentation](../index.md) / RouteRecordMultipleViewsWithChildren + +# Interface: RouteRecordMultipleViewsWithChildren + +Route Record defining multiple named components with the `components` option and children. + +## Hierarchy + +- [`_RouteRecordBase`](RouteRecordBase.md) + + ↳ **`RouteRecordMultipleViewsWithChildren`** + +## Properties + +### alias + +• `Optional` **alias**: `string` \| `string`[] + +Aliases for the record. Allows defining extra paths that will behave like a +copy of the record. Allows having paths shorthands like `/users/:id` and +`/u/:id`. All `alias` and `path` values must share the same params. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[alias](RouteRecordBase.md#alias) + +___ + +### beforeEnter + +• `Optional` **beforeEnter**: [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\> \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\>[] + +Before Enter guard specific to this record. Note `beforeEnter` has no +effect if the record has a `redirect` property. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[beforeEnter](RouteRecordBase.md#beforeEnter) + +___ + +### children + +• **children**: [`RouteRecordRaw`](../index.md#RouteRecordRaw)[] + +Array of nested routes. + +#### Overrides + +[_RouteRecordBase](RouteRecordBase.md).[children](RouteRecordBase.md#children) + +___ + +### component + +• `Optional` **component**: `undefined` + +___ + +### components + +• `Optional` **components**: ``null`` \| `Record`\<`string`, `RawRouteComponent`\> + +Components to display when the URL matches this route. Allow using named views. + +___ + +### end + +• `Optional` **end**: `boolean` + +Should the RegExp match until the end by appending a `$` to it. + +**`Default Value`** + +`true` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[end](RouteRecordBase.md#end) + +___ + +### meta + +• `Optional` **meta**: [`RouteMeta`](RouteMeta.md) + +Arbitrary data attached to the record. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[meta](RouteRecordBase.md#meta) + +___ + +### name + +• `Optional` **name**: [`RouteRecordName`](../index.md#RouteRecordName) + +Name for the route record. Must be unique. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[name](RouteRecordBase.md#name) + +___ + +### path + +• **path**: `string` + +Path of the record. Should start with `/` unless the record is the child of +another record. + +**`Example`** + +```ts +`/users/:id` matches `/users/1` as well as `/users/posva`. +``` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[path](RouteRecordBase.md#path) + +___ + +### props + +• `Optional` **props**: `boolean` \| `Record`\<`string`, `_RouteRecordProps`\> + +Allow passing down params as props to the component rendered by +`router-view`. Should be an object with the same keys as `components` or a +boolean to be applied to every component. + +#### Overrides + +[_RouteRecordBase](RouteRecordBase.md).[props](RouteRecordBase.md#props) + +___ + +### redirect + +• `Optional` **redirect**: `RouteRecordRedirectOption` + +Where to redirect if the route is directly matched. The redirection happens +before any navigation guard and triggers a new navigation with the new +target location. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[redirect](RouteRecordBase.md#redirect) + +___ + +### sensitive + +• `Optional` **sensitive**: `boolean` + +Makes the RegExp case-sensitive. + +**`Default Value`** + +`false` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[sensitive](RouteRecordBase.md#sensitive) + +___ + +### strict + +• `Optional` **strict**: `boolean` + +Whether to disallow a trailing slash or not. + +**`Default Value`** + +`false` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[strict](RouteRecordBase.md#strict) diff --git a/packages/docs/zh/api/interfaces/RouteRecordNormalized.md b/packages/docs/zh/api/interfaces/RouteRecordNormalized.md index 4ac724ed3..833843889 100644 --- a/packages/docs/zh/api/interfaces/RouteRecordNormalized.md +++ b/packages/docs/zh/api/interfaces/RouteRecordNormalized.md @@ -26,7 +26,7 @@ ___ ### beforeEnter %{#Properties-beforeEnter}% -• **beforeEnter**: `undefined` \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)<`undefined`\> \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)<`undefined`\>[] +• **beforeEnter**: `undefined` \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\> \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\>[] 被注册的 beforeEnter 守卫 @@ -42,15 +42,15 @@ ___ ### components %{#Properties-components}% -• **components**: `undefined` \| ``null`` \| `Record`<`string`, `RawRouteComponent`\> +• **components**: `undefined` \| ``null`` \| `Record`\<`string`, `RawRouteComponent`\> -{@inheritDoc RouteRecordMultipleViews.components} +Components to display when the URL matches this route. Allow using named views. ___ ### instances %{#Properties-instances}% -• **instances**: `Record`<`string`, `undefined` \| ``null`` \| `ComponentPublicInstance`<{}, {}, {}, {}, {}, {}, {}, {}, ``false``, `ComponentOptionsBase`<`any`, `any`, `any`, `any`, `any`, `any`, `any`, `any`, `any`, {}, {}, `string`\>, {}\>\> +• **instances**: `Record`\<`string`, `undefined` \| ``null`` \| `ComponentPublicInstance`\> @@ -68,7 +68,9 @@ ___ • **meta**: [`RouteMeta`](RouteMeta.md) -{@inheritDoc _RouteRecordBase.meta} + + +Arbitrary data attached to the record. ___ @@ -76,7 +78,9 @@ ___ • **name**: `undefined` \| [`RouteRecordName`](../index.md#routerecordname) -{@inheritDoc _RouteRecordBase.name} + + +Name for the route record. Must be unique. ___ @@ -84,15 +88,19 @@ ___ • **path**: `string` -{@inheritDoc _RouteRecordBase.path} + + +Path of the record. Should start with `/` unless the record is the child of another record. ___ ### props %{#Properties-props}% -• **props**: `Record`<`string`, `_RouteRecordProps`\> +• **props**: `Record`\<`string`, `_RouteRecordProps`\> + + -{@inheritDoc RouteRecordMultipleViews.props} +Allow passing down params as props to the component rendered by `router-view`. Should be an object with the same keys as `components` or a boolean to be applied to every component. ___ @@ -100,4 +108,6 @@ ___ • **redirect**: `undefined` \| `RouteRecordRedirectOption` -{@inheritDoc _RouteRecordBase.redirect} + + +Where to redirect if the route is directly matched. The redirection happens before any navigation guard and triggers a new navigation with the new target location. diff --git a/packages/docs/zh/api/interfaces/RouteRecordRedirect.md b/packages/docs/zh/api/interfaces/RouteRecordRedirect.md new file mode 100644 index 000000000..3c5029483 --- /dev/null +++ b/packages/docs/zh/api/interfaces/RouteRecordRedirect.md @@ -0,0 +1,186 @@ +--- +editLink: false +--- + + + +[API Documentation](../index.md) / RouteRecordRedirect + +# Interface: RouteRecordRedirect + +Route Record that defines a redirect. Cannot have `component` or `components` +as it is never rendered. + +## Hierarchy + +- [`_RouteRecordBase`](RouteRecordBase.md) + + ↳ **`RouteRecordRedirect`** + +## Properties + +### alias + +• `Optional` **alias**: `string` \| `string`[] + +Aliases for the record. Allows defining extra paths that will behave like a +copy of the record. Allows having paths shorthands like `/users/:id` and +`/u/:id`. All `alias` and `path` values must share the same params. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[alias](RouteRecordBase.md#alias) + +___ + +### beforeEnter + +• `Optional` **beforeEnter**: [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\> \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\>[] + +Before Enter guard specific to this record. Note `beforeEnter` has no +effect if the record has a `redirect` property. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[beforeEnter](RouteRecordBase.md#beforeEnter) + +___ + +### children + +• `Optional` **children**: [`RouteRecordRaw`](../index.md#RouteRecordRaw)[] + +Array of nested routes. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[children](RouteRecordBase.md#children) + +___ + +### component + +• `Optional` **component**: `undefined` + +___ + +### components + +• `Optional` **components**: `undefined` + +___ + +### end + +• `Optional` **end**: `boolean` + +Should the RegExp match until the end by appending a `$` to it. + +**`Default Value`** + +`true` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[end](RouteRecordBase.md#end) + +___ + +### meta + +• `Optional` **meta**: [`RouteMeta`](RouteMeta.md) + +Arbitrary data attached to the record. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[meta](RouteRecordBase.md#meta) + +___ + +### name + +• `Optional` **name**: [`RouteRecordName`](../index.md#RouteRecordName) + +Name for the route record. Must be unique. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[name](RouteRecordBase.md#name) + +___ + +### path + +• **path**: `string` + +Path of the record. Should start with `/` unless the record is the child of +another record. + +**`Example`** + +```ts +`/users/:id` matches `/users/1` as well as `/users/posva`. +``` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[path](RouteRecordBase.md#path) + +___ + +### props + +• `Optional` **props**: `undefined` + +Allow passing down params as props to the component rendered by `router-view`. + +#### Overrides + +[_RouteRecordBase](RouteRecordBase.md).[props](RouteRecordBase.md#props) + +___ + +### redirect + +• **redirect**: `RouteRecordRedirectOption` + +Where to redirect if the route is directly matched. The redirection happens +before any navigation guard and triggers a new navigation with the new +target location. + +#### Overrides + +[_RouteRecordBase](RouteRecordBase.md).[redirect](RouteRecordBase.md#redirect) + +___ + +### sensitive + +• `Optional` **sensitive**: `boolean` + +Makes the RegExp case-sensitive. + +**`Default Value`** + +`false` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[sensitive](RouteRecordBase.md#sensitive) + +___ + +### strict + +• `Optional` **strict**: `boolean` + +Whether to disallow a trailing slash or not. + +**`Default Value`** + +`false` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[strict](RouteRecordBase.md#strict) diff --git a/packages/docs/zh/api/interfaces/RouteRecordSingleView.md b/packages/docs/zh/api/interfaces/RouteRecordSingleView.md new file mode 100644 index 000000000..d498116d2 --- /dev/null +++ b/packages/docs/zh/api/interfaces/RouteRecordSingleView.md @@ -0,0 +1,187 @@ +--- +editLink: false +--- + + + +[API Documentation](../index.md) / RouteRecordSingleView + +# Interface: RouteRecordSingleView + +Route Record defining one single component with the `component` option. + +## Hierarchy + +- [`_RouteRecordBase`](RouteRecordBase.md) + + ↳ **`RouteRecordSingleView`** + +## Properties + +### alias + +• `Optional` **alias**: `string` \| `string`[] + +Aliases for the record. Allows defining extra paths that will behave like a +copy of the record. Allows having paths shorthands like `/users/:id` and +`/u/:id`. All `alias` and `path` values must share the same params. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[alias](RouteRecordBase.md#alias) + +___ + +### beforeEnter + +• `Optional` **beforeEnter**: [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\> \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\>[] + +Before Enter guard specific to this record. Note `beforeEnter` has no +effect if the record has a `redirect` property. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[beforeEnter](RouteRecordBase.md#beforeEnter) + +___ + +### children + +• `Optional` **children**: `undefined` + +Array of nested routes. + +#### Overrides + +[_RouteRecordBase](RouteRecordBase.md).[children](RouteRecordBase.md#children) + +___ + +### component + +• **component**: `RawRouteComponent` + +Component to display when the URL matches this route. + +___ + +### components + +• `Optional` **components**: `undefined` + +___ + +### end + +• `Optional` **end**: `boolean` + +Should the RegExp match until the end by appending a `$` to it. + +**`Default Value`** + +`true` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[end](RouteRecordBase.md#end) + +___ + +### meta + +• `Optional` **meta**: [`RouteMeta`](RouteMeta.md) + +Arbitrary data attached to the record. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[meta](RouteRecordBase.md#meta) + +___ + +### name + +• `Optional` **name**: [`RouteRecordName`](../index.md#RouteRecordName) + +Name for the route record. Must be unique. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[name](RouteRecordBase.md#name) + +___ + +### path + +• **path**: `string` + +Path of the record. Should start with `/` unless the record is the child of +another record. + +**`Example`** + +```ts +`/users/:id` matches `/users/1` as well as `/users/posva`. +``` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[path](RouteRecordBase.md#path) + +___ + +### props + +• `Optional` **props**: `_RouteRecordProps` + +Allow passing down params as props to the component rendered by `router-view`. + +#### Overrides + +[_RouteRecordBase](RouteRecordBase.md).[props](RouteRecordBase.md#props) + +___ + +### redirect + +• `Optional` **redirect**: `undefined` + +Where to redirect if the route is directly matched. The redirection happens +before any navigation guard and triggers a new navigation with the new +target location. + +#### Overrides + +[_RouteRecordBase](RouteRecordBase.md).[redirect](RouteRecordBase.md#redirect) + +___ + +### sensitive + +• `Optional` **sensitive**: `boolean` + +Makes the RegExp case-sensitive. + +**`Default Value`** + +`false` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[sensitive](RouteRecordBase.md#sensitive) + +___ + +### strict + +• `Optional` **strict**: `boolean` + +Whether to disallow a trailing slash or not. + +**`Default Value`** + +`false` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[strict](RouteRecordBase.md#strict) diff --git a/packages/docs/zh/api/interfaces/RouteRecordSingleViewWithChildren.md b/packages/docs/zh/api/interfaces/RouteRecordSingleViewWithChildren.md new file mode 100644 index 000000000..e9430ee61 --- /dev/null +++ b/packages/docs/zh/api/interfaces/RouteRecordSingleViewWithChildren.md @@ -0,0 +1,187 @@ +--- +editLink: false +--- + + + +[API Documentation](../index.md) / RouteRecordSingleViewWithChildren + +# Interface: RouteRecordSingleViewWithChildren + +Route Record defining one single component with a nested view. + +## Hierarchy + +- [`_RouteRecordBase`](RouteRecordBase.md) + + ↳ **`RouteRecordSingleViewWithChildren`** + +## Properties + +### alias + +• `Optional` **alias**: `string` \| `string`[] + +Aliases for the record. Allows defining extra paths that will behave like a +copy of the record. Allows having paths shorthands like `/users/:id` and +`/u/:id`. All `alias` and `path` values must share the same params. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[alias](RouteRecordBase.md#alias) + +___ + +### beforeEnter + +• `Optional` **beforeEnter**: [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\> \| [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\>[] + +Before Enter guard specific to this record. Note `beforeEnter` has no +effect if the record has a `redirect` property. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[beforeEnter](RouteRecordBase.md#beforeEnter) + +___ + +### children + +• **children**: [`RouteRecordRaw`](../index.md#RouteRecordRaw)[] + +Array of nested routes. + +#### Overrides + +[_RouteRecordBase](RouteRecordBase.md).[children](RouteRecordBase.md#children) + +___ + +### component + +• `Optional` **component**: ``null`` \| `RawRouteComponent` + +Component to display when the URL matches this route. + +___ + +### components + +• `Optional` **components**: `undefined` + +___ + +### end + +• `Optional` **end**: `boolean` + +Should the RegExp match until the end by appending a `$` to it. + +**`Default Value`** + +`true` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[end](RouteRecordBase.md#end) + +___ + +### meta + +• `Optional` **meta**: [`RouteMeta`](RouteMeta.md) + +Arbitrary data attached to the record. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[meta](RouteRecordBase.md#meta) + +___ + +### name + +• `Optional` **name**: [`RouteRecordName`](../index.md#RouteRecordName) + +Name for the route record. Must be unique. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[name](RouteRecordBase.md#name) + +___ + +### path + +• **path**: `string` + +Path of the record. Should start with `/` unless the record is the child of +another record. + +**`Example`** + +```ts +`/users/:id` matches `/users/1` as well as `/users/posva`. +``` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[path](RouteRecordBase.md#path) + +___ + +### props + +• `Optional` **props**: `_RouteRecordProps` + +Allow passing down params as props to the component rendered by `router-view`. + +#### Overrides + +[_RouteRecordBase](RouteRecordBase.md).[props](RouteRecordBase.md#props) + +___ + +### redirect + +• `Optional` **redirect**: `RouteRecordRedirectOption` + +Where to redirect if the route is directly matched. The redirection happens +before any navigation guard and triggers a new navigation with the new +target location. + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[redirect](RouteRecordBase.md#redirect) + +___ + +### sensitive + +• `Optional` **sensitive**: `boolean` + +Makes the RegExp case-sensitive. + +**`Default Value`** + +`false` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[sensitive](RouteRecordBase.md#sensitive) + +___ + +### strict + +• `Optional` **strict**: `boolean` + +Whether to disallow a trailing slash or not. + +**`Default Value`** + +`false` + +#### Inherited from + +[_RouteRecordBase](RouteRecordBase.md).[strict](RouteRecordBase.md#strict) \ No newline at end of file diff --git a/packages/docs/zh/api/interfaces/Router.md b/packages/docs/zh/api/interfaces/Router.md index ae8f773bd..6978460ad 100644 --- a/packages/docs/zh/api/interfaces/Router.md +++ b/packages/docs/zh/api/interfaces/Router.md @@ -14,7 +14,7 @@ editLink: false ### currentRoute %{#Properties-currentRoute}% -• `只读` **currentRoute**: `Ref`<[`RouteLocationNormalizedLoaded`](RouteLocationNormalizedLoaded.md)\> +• `只读` **currentRoute**: `Ref`\<[`RouteLocationNormalizedLoaded`](RouteLocationNormalizedLoaded.md)\> 当前的 [RouteLocationNormalized](RouteLocationNormalized.md)。 @@ -91,16 +91,6 @@ ___ 添加一个导航钩子,它会在每次导航之后被执行。返回一个用来移除该钩子的函数。 -**`Example`** - -```js -router.afterEach((to, from, failure) => { - if (isNavigationFailure(failure)) { - console.log('failed navigation', failure) - } -}) -``` - #### 参数 %{#Methods-afterEach-Parameters}% | 名称 | 类型 | 描述 | @@ -111,6 +101,8 @@ router.afterEach((to, from, failure) => { `fn` +a function that removes the registered hook + ▸ (): `void` 添加一个导航钩子,它会在每次导航之后被执行。返回一个用来移除该钩子的函数。 @@ -153,7 +145,7 @@ ___ | 名称 | 类型 | 描述 | | :------ | :------ | :------ | -| `guard` | [`NavigationGuardWithThis`](NavigationGuardWithThis.md)<`undefined`\> | 要加入的导航钩子 | +| `guard` | [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\> | 要加入的导航钩子 | #### 返回值 %{#Methods-beforeEach-Returns}% @@ -175,19 +167,11 @@ ___ 添加一个导航守卫,它会在导航将要被解析之前被执行。此时所有组件都已经获取完毕,且其它导航守卫也都已经完成调用。返回一个用来移除该守卫的函数。 -**`Example`** - -```js -router.beforeResolve(to => { - if (to.meta.requiresAuth && !isAuthenticated) return false -}) -``` - #### 参数 %{#Methods-beforeResolve-Parameters}% | 名称 | 类型 | 描述 | | :------ | :------ | :------ | -| `guard` | [`NavigationGuardWithThis`](NavigationGuardWithThis.md)<`undefined`\> | navigation guard to add | +| `guard` | [`NavigationGuardWithThis`](NavigationGuardWithThis.md)\<`undefined`\> | navigation guard to add | #### 返回值 %{#Methods-beforeResolve-Returns}% @@ -273,7 +257,7 @@ ___ ### isReady %{#Methods-isReady}% -▸ **isReady**(): `Promise`<`void`\> +▸ **isReady**(): `Promise`\<`void`\> 返回一个 Promise,它会在路由器完成初始导航之后被解析,也就是说这时所有和初始路由有关联的异步入口钩子和异步组件都已经被解析。如果初始导航已经发生,则该 Promise 会被立刻解析。 @@ -281,7 +265,7 @@ ___ #### 返回值 %{#Methods-isReady-Returns}% -`Promise`<`void`\> +`Promise`\<`void`\> ___ @@ -295,7 +279,7 @@ ___ | 名称 | 类型 | 描述 | | :------ | :------ | :------ | -| `handler` | `_ErrorHandler` | 要注册的错误处理器 | +| `handler` | `_ErrorListener` | 要注册的错误处理器 | #### 返回值 %{#Methods-onError-Returns}% @@ -313,7 +297,7 @@ ___ ### push %{#Methods-push}% -▸ **push**(`to`): `Promise`<`undefined` \| `void` \| [`NavigationFailure`](NavigationFailure.md)\> +▸ **push**(`to`): `Promise`\<`undefined` \| `void` \| [`NavigationFailure`](NavigationFailure.md)\> 程序式地通过将一条记录加入到历史栈中来导航到一个新的 URL。 @@ -325,7 +309,7 @@ ___ #### 返回值 %{#Methods-push-Returns}% -`Promise`<`undefined` \| `void` \| [`NavigationFailure`](NavigationFailure.md)\> +`Promise`\<`undefined` \| `void` \| [`NavigationFailure`](NavigationFailure.md)\> ___ @@ -349,7 +333,7 @@ ___ ### replace %{#Methods-replace}% -▸ **replace**(`to`): `Promise`<`undefined` \| `void` \| [`NavigationFailure`](NavigationFailure.md)\> +▸ **replace**(`to`): `Promise`\<`undefined` \| `void` \| [`NavigationFailure`](NavigationFailure.md)\> 程序式地通过替换历史栈中的当前记录来导航到一个新的 URL。 @@ -361,7 +345,7 @@ ___ #### 返回值 %{#Methods-replace-Returns}% -`Promise`<`undefined` \| `void` \| [`NavigationFailure`](NavigationFailure.md)\> +`Promise`\<`undefined` \| `void` \| [`NavigationFailure`](NavigationFailure.md)\> ___ diff --git a/packages/docs/zh/api/interfaces/RouterHistory.md b/packages/docs/zh/api/interfaces/RouterHistory.md index 8f94710d8..ec557c818 100644 --- a/packages/docs/zh/api/interfaces/RouterHistory.md +++ b/packages/docs/zh/api/interfaces/RouterHistory.md @@ -70,13 +70,6 @@ ___ 按指定方向访问历史。 -**`Example`** - -```js -myHistory.go(-1) // equivalent to window.history.back() -myHistory.go(1) // equivalent to window.history.forward() -``` - #### 参数 %{#Methods-go-Parameters}% | 名称 | 类型 | 描述 | @@ -88,6 +81,13 @@ myHistory.go(1) // equivalent to window.history.forward() `void` +**`Example`** + +```js +myHistory.go(-1) // equivalent to window.history.back() +myHistory.go(1) // equivalent to window.history.forward() +``` + ___ ### listen %{#Methods-listen}% @@ -143,7 +143,7 @@ ___ ▸ **replace**(`to`, `data?`): `void` -和 [push](RouterHistory.md#push) 相同,只是执行了 `history.replaceState` +和 [RouterHistory.push](RouterHistory.md#push) 相同,只是执行了 `history.replaceState` 以换掉 `history.pushState`。 #### 参数 %{#Methods-replace-Parameters}% diff --git a/packages/docs/zh/api/interfaces/RouterOptions.md b/packages/docs/zh/api/interfaces/RouterOptions.md index a713881aa..0f0229f59 100644 --- a/packages/docs/zh/api/interfaces/RouterOptions.md +++ b/packages/docs/zh/api/interfaces/RouterOptions.md @@ -73,7 +73,17 @@ ___ ▸ (`search`): [`LocationQuery`](../index.md#locationquery) -解析查询的自定义实现。请查阅其相关内容 [stringifyQuery](RouterOptions.md#stringifyquery)。 +解析查询的自定义实现。请查阅其相关内容 [RouterOptions.stringifyQuery](RouterOptions.md#stringifyquery)。 + +##### 参数 %{#Properties-parseQuery-Type-declaration-Parameters}% + +| 名称 | 类型 | +| :------ | :------ | +| `search` | `string` | + +##### 返回值 %{#Properties-parseQuery-Type-declaration-Returns}% + +[`LocationQuery`](../index.md#locationquery) **`示例`** @@ -89,16 +99,6 @@ createRouter({ }) ``` -##### 参数 %{#Properties-parseQuery-Type-declaration-Parameters}% - -| 名称 | 类型 | -| :------ | :------ | -| `search` | `string` | - -##### 返回值 %{#Properties-parseQuery-Type-declaration-Returns}% - -[`LocationQuery`](../index.md#locationquery) - ___ ### routes %{#Properties-routes}% diff --git a/packages/docs/zh/api/interfaces/RouterScrollBehavior.md b/packages/docs/zh/api/interfaces/RouterScrollBehavior.md index c0eb1742b..4092cee43 100644 --- a/packages/docs/zh/api/interfaces/RouterScrollBehavior.md +++ b/packages/docs/zh/api/interfaces/RouterScrollBehavior.md @@ -6,11 +6,15 @@ editLink: false # 接口:RouterScrollBehavior + + +Type of the `scrollBehavior` option that can be passed to `createRouter`. + ## 可调用函数 %{#Callable}% ### RouterScrollBehavior %{#Callable-RouterScrollBehavior}% -▸ **RouterScrollBehavior**(`to`, `from`, `savedPosition`): `Awaitable`<``false`` \| `void` \| `ScrollPosition`\> +▸ **RouterScrollBehavior**(`to`, `from`, `savedPosition`): `Awaitable`\<``false`` \| `void` \| `ScrollPosition`\> #### 参数 %{#Callable-RouterScrollBehavior-Parameters}% @@ -22,4 +26,4 @@ editLink: false #### 返回值 %{#Callable-RouterScrollBehavior-Returns}% -`Awaitable`<``false`` \| `void` \| `ScrollPosition`\> +`Awaitable`\<``false`` \| `void` \| `ScrollPosition`\> diff --git a/packages/docs/zh/guide/advanced/dynamic-routing.md b/packages/docs/zh/guide/advanced/dynamic-routing.md index 5ad3bcace..380b7f22a 100644 --- a/packages/docs/zh/guide/advanced/dynamic-routing.md +++ b/packages/docs/zh/guide/advanced/dynamic-routing.md @@ -5,7 +5,7 @@ title="Learn how to add routes at runtime" /> -对路由的添加通常是通过 [`routes` 选项](../../api/#routes)来完成的,但是在某些情况下,你可能想在应用程序已经运行的时候添加或删除路由。具有可扩展接口(如 [Vue CLI UI](https://cli.vuejs.org/dev-guide/ui-api.html) )这样的应用程序可以使用它来扩展应用程序。 +对路由的添加通常是通过 `routes` 选项来完成的,但是在某些情况下,你可能想在应用程序已经运行的时候添加或删除路由。具有可扩展接口(如 [Vue CLI UI](https://cli.vuejs.org/dev-guide/ui-api.html) )这样的应用程序可以使用它来扩展应用程序。 ## 添加路由 diff --git a/packages/docs/zh/guide/advanced/lazy-loading.md b/packages/docs/zh/guide/advanced/lazy-loading.md index c4e0dffdf..80e2829d2 100644 --- a/packages/docs/zh/guide/advanced/lazy-loading.md +++ b/packages/docs/zh/guide/advanced/lazy-loading.md @@ -17,7 +17,11 @@ const UserDetails = () => import('./views/UserDetails.vue') const router = createRouter({ // ... - routes: [{ path: '/users/:id', component: UserDetails }], + routes: [ + { path: '/users/:id', component: UserDetails } + // 或在路由定义里直接使用它 + { path: '/users/:id', component: () => import('./views/UserDetails.vue') }, + ], }) ``` diff --git a/packages/docs/zh/guide/advanced/meta.md b/packages/docs/zh/guide/advanced/meta.md index a2a53094b..84f909725 100644 --- a/packages/docs/zh/guide/advanced/meta.md +++ b/packages/docs/zh/guide/advanced/meta.md @@ -17,13 +17,13 @@ const routes = [ path: 'new', component: PostsNew, // 只有经过身份验证的用户才能创建帖子 - meta: { requiresAuth: true } + meta: { requiresAuth: true }, }, { path: ':id', component: PostsDetail // 任何人都可以阅读文章 - meta: { requiresAuth: false } + meta: { requiresAuth: false }, } ] } @@ -58,12 +58,19 @@ router.beforeEach((to, from) => { ## TypeScript -可以通过扩展 `RouteMeta` 接口来输入 meta 字段: + + +It is possible to type the meta field by extending the `RouteMeta` interface from `vue-router`: ```ts -// typings.d.ts or router.ts +// This can be directly added to any of your `.ts` files like `router.ts` +// It can also be added to a `.d.ts` file. Make sure it's included in +// project's tsconfig.json "files" import 'vue-router' +// To ensure it is treated as a module, add at least one `export` statement +export {} + declare module 'vue-router' { interface RouteMeta { // 是可选的 diff --git a/packages/docs/zh/guide/advanced/navigation-failures.md b/packages/docs/zh/guide/advanced/navigation-failures.md index c9cb90da7..b1bfe9d37 100644 --- a/packages/docs/zh/guide/advanced/navigation-failures.md +++ b/packages/docs/zh/guide/advanced/navigation-failures.md @@ -62,6 +62,20 @@ if (isNavigationFailure(failure, NavigationFailureType.aborted)) { 如果你忽略第二个参数: `isNavigationFailure(failure)`,那么就只会检查这个 `failure` 是不是一个 _Navigation Failure_。 ::: + + +## Global navigation failures + +You can detect global navigation failures globally by using the [`router.afterEach()` navigation guard](./navigation-guards.md#Global-After-Hooks): + +```ts +router.afterEach((to, from, failure) => { + if (failure) { + sendToAnalytics(to, from, failure) + } +}) +``` + ## 鉴别导航故障 正如我们在一开始所说的,有不同的情况会导致导航的中止,所有这些情况都会导致不同的 _Navigation Failure_。它们可以用 `isNavigationFailure` 和 `NavigationFailureType` 来区分。总共有三种不同的类型: diff --git a/packages/docs/zh/guide/advanced/navigation-guards.md b/packages/docs/zh/guide/advanced/navigation-guards.md index 3f56595d2..625e1d7e7 100644 --- a/packages/docs/zh/guide/advanced/navigation-guards.md +++ b/packages/docs/zh/guide/advanced/navigation-guards.md @@ -31,7 +31,7 @@ router.beforeEach((to, from) => { 可以返回的值如下: - `false`: 取消当前的导航。如果浏览器的 URL 改变了(可能是用户手动或者浏览器后退按钮),那么 URL 地址会重置到 `from` 路由对应的地址。 -- 一个[路由地址](../../api/#routelocationraw): 通过一个路由地址重定向到一个不同的地址,如同调用 [`router.push()`](../../api/#push),且可以传入诸如 `replace: true` 或 `name: 'home'` 之类的选项。它会中断当前的导航,同时用相同的 `from` 创建一个新导航。 +- 一个[路由地址](../../api/#routelocationraw): 通过一个路由地址重定向到一个不同的地址,如同调用 `router.push()`,且可以传入诸如 `replace: true` 或 `name: 'home'` 之类的选项。它会中断当前的导航,同时用相同的 `from` 创建一个新导航。 ```js router.beforeEach(async (to, from) => { @@ -47,7 +47,7 @@ router.beforeEach((to, from) => { }) ``` -如果遇到了意料之外的情况,可能会抛出一个 `Error`。这会取消导航并且调用 [`router.onError()`](../../api/#onerror) 注册过的回调。 +如果遇到了意料之外的情况,可能会抛出一个 `Error`。这会取消导航并且调用 [`router.onError()`](../../api/interfaces/Router.md#onError) 注册过的回调。 如果什么都没有,`undefined` 或返回 `true`,**则导航是有效的**,并调用下一个导航守卫 @@ -134,6 +134,26 @@ router.afterEach((to, from, failure) => { 了解更多关于 navigation failures 的信息在[它的指南](./navigation-failures.md)中。 + + +## Global injections within guards + +Since Vue 3.3, it is possible to use `inject()` within navigation guards. This is useful for injecting global properties like the [pinia stores](https://pinia.vuejs.org). Anything that is provided with `app.provide()` is also accessible within `router.beforeEach()`, `router.beforeResolve()`, `router.afterEach()`: + +```ts +// main.ts +const app = createApp(App) +app.provide('global', 'hello injections') + +// router.ts or main.ts +router.beforeEach((to, from) => { + const global = inject('global') // 'hello injections' + // a pinia store + const userStore = useAuthStore() + // ... +}) +``` + ## 路由独享的守卫 你可以直接在路由配置上定义 `beforeEnter` 守卫: @@ -179,7 +199,7 @@ const routes = [ ] ``` -请注意,你也可以通过使用[路径 meta 字段](./meta.md)和[全局导航守卫](#global-before-guards)来实现类似的行为。 +请注意,你也可以通过使用[路径 meta 字段](./meta.md)和全局导航守卫来实现类似的行为。 ## 组件内的守卫 diff --git a/packages/docs/zh/guide/advanced/router-view-slot.md b/packages/docs/zh/guide/advanced/router-view-slot.md new file mode 100644 index 000000000..49b7d57f9 --- /dev/null +++ b/packages/docs/zh/guide/advanced/router-view-slot.md @@ -0,0 +1,75 @@ + + +# RouterView slot + +The RouterView component exposes a slot that can be used to render the route component: + +```vue-html + + + +``` + +The code above is equivalent to using `` without the slot, but the slot provides extra flexibility when we want to work with other features. + +## KeepAlive & Transition + +When working with the [KeepAlive](https://vuejs.org/guide/built-ins/keep-alive.html) component, we would usually want it to keep the route components alive, not the RouterView itself. We can achieve that by putting the KeepAlive inside the slot: + +```vue-html + + + + + +``` + +Similarly, the slot allows us to use a [Transition](https://vuejs.org/guide/built-ins/transition.html) component to transition between route components: + +```vue-html + + + + + +``` + +We can also use KeepAlive inside a Transition: + +```vue-html + + + + + + + +``` + +For more information about using RouterView with the Transition component, see the [Transitions](./transitions) guide. + +## Passing props and slots + +We can use the slot to pass props or slots to the route component: + +```vue-html + + +

Some slotted content

+
+
+``` + +In practice, this usually isn't something you would want to do, as the route components would **all need to use the same props and slots**. See [Passing Props to Route Components](../essentials/passing-props) for other ways to pass props. + +## Template refs + +Using the slot allows us to put a [template ref](https://vuejs.org/guide/essentials/template-refs.html) directly on the route component: + +```vue-html + + + +``` + +If we put the ref on the `` instead then the ref would be populated with the RouterView instance, rather than the route component. diff --git a/packages/docs/zh/guide/advanced/scroll-behavior.md b/packages/docs/zh/guide/advanced/scroll-behavior.md index c34d043db..f0d77b19a 100644 --- a/packages/docs/zh/guide/advanced/scroll-behavior.md +++ b/packages/docs/zh/guide/advanced/scroll-behavior.md @@ -43,7 +43,8 @@ const router = createRouter({ // 也可以这么写 // el: document.getElementById('main'), el: '#main', - top: -10, + // 在元素上 10 像素 + top: 10, } }, }) diff --git a/packages/docs/zh/guide/advanced/transitions.md b/packages/docs/zh/guide/advanced/transitions.md index cc10eebcc..aaabd9e39 100644 --- a/packages/docs/zh/guide/advanced/transitions.md +++ b/packages/docs/zh/guide/advanced/transitions.md @@ -5,9 +5,9 @@ title="Learn about route transitions" /> -想要在你的路径组件上使用转场,并对导航进行动画处理,你需要使用 [v-slot API](/guide/advanced/composition-api#uselink): +想要在你的路径组件上使用转场,并对导航进行动画处理,你需要使用 [`` 插槽](./router-view-slot): -```vue-html +```html @@ -36,7 +36,7 @@ const routes = [ ] ``` -```vue-html +```html @@ -49,7 +49,7 @@ const routes = [ 也可以根据目标路由和当前路由之间的关系,动态地确定使用的过渡。使用和刚才非常相似的片段: -```vue-html +```html diff --git a/packages/docs/zh/guide/essentials/history-mode.md b/packages/docs/zh/guide/essentials/history-mode.md index edc44085c..888cb68cb 100644 --- a/packages/docs/zh/guide/essentials/history-mode.md +++ b/packages/docs/zh/guide/essentials/history-mode.md @@ -24,6 +24,24 @@ const router = createRouter({ 它在内部传递的实际 URL 之前使用了一个哈希字符(`#`)。由于这部分 URL 从未被发送到服务器,所以它不需要在服务器层面上进行任何特殊处理。不过,**它在 SEO 中确实有不好的影响**。如果你担心这个问题,可以使用 HTML5 模式。 + + +## Memory mode + +The memory history mode doesn't assume a browser environment and therefore doesn't interact with the URL **nor automatically triggers the initial navigation**. This makes it perfect for Node environment and SSR. It is created with `createMemoryHistory()` and **requires you to push the initial navigation** after calling `app.use(router)`. + +```js +import { createRouter, createMemoryHistory } from 'vue-router' +const router = createRouter({ + history: createMemoryHistory(), + routes: [ + //... + ], +}) +``` + +While it's not recommended, you can use this mode inside Browser applications but note **there will be no history**, meaning you won't be able to go _back_ or _forward_. + ## HTML5 模式 用 `createWebHistory()` 创建 HTML5 模式,推荐使用这个模式: @@ -66,7 +84,7 @@ const router = createRouter({ ``` -也可以使用 [`FallbackResource`](https://httpd.apache.org/docs/2.2/mod/mod_dir.html#fallbackresource) 代替 `mod_rewrite`。 +也可以使用 [`FallbackResource`](https://httpd.apache.org/docs/2.4/mod/mod_dir.html#fallbackresource) 代替 `mod_rewrite`。 ### nginx diff --git a/packages/docs/zh/guide/essentials/named-routes.md b/packages/docs/zh/guide/essentials/named-routes.md index 4541f3700..81bb0b60f 100644 --- a/packages/docs/zh/guide/essentials/named-routes.md +++ b/packages/docs/zh/guide/essentials/named-routes.md @@ -24,7 +24,7 @@ const routes = [ 要链接到一个命名的路由,可以向 `router-link` 组件的 `to` 属性传递一个对象: -```vue-html +```html User @@ -39,3 +39,7 @@ router.push({ name: 'user', params: { username: 'erina' } }) 在这两种情况下,路由将导航到路径 `/user/erina`。 完整的例子在[这里](https://github.com/vuejs/vue-router/blob/dev/examples/named-routes/app.js). + + + +Each name **must be unique** across all routes. If you add the same name to multiple routes, the router will only keep the last one. You can read more about this [in the Dynamic Routing](../advanced/dynamic-routing.md#Removing-routes) section. diff --git a/packages/docs/zh/guide/essentials/named-views.md b/packages/docs/zh/guide/essentials/named-views.md index e87f9eb25..11e8f5f18 100644 --- a/packages/docs/zh/guide/essentials/named-views.md +++ b/packages/docs/zh/guide/essentials/named-views.md @@ -7,7 +7,7 @@ 有时候想同时 (同级) 展示多个视图,而不是嵌套展示,例如创建一个布局,有 `sidebar` (侧导航) 和 `main` (主内容) 两个视图,这个时候命名视图就派上用场了。你可以在界面中拥有多个单独命名的视图,而不是只有一个单独的出口。如果 `router-view` 没有设置名字,那么默认为 `default`。 -```vue-html +```html @@ -59,7 +59,7 @@ const router = createRouter({ `UserSettings` 组件的 `