From: Eduardo San Martin Morote Date: Fri, 14 Jul 2023 13:24:43 +0000 (+0200) Subject: docs: mention in more places that names are unique. X-Git-Tag: v4.2.5~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1cb459422e210c4d4fd9b8b902849e9b82a9c1ba;p=thirdparty%2Fvuejs%2Frouter.git docs: mention in more places that names are unique. As pointed out in vuejs/router#1930 --- diff --git a/packages/docs/guide/advanced/dynamic-routing.md b/packages/docs/guide/advanced/dynamic-routing.md index 86fd3aac..17fab1ea 100644 --- a/packages/docs/guide/advanced/dynamic-routing.md +++ b/packages/docs/guide/advanced/dynamic-routing.md @@ -62,7 +62,8 @@ There are few different ways to remove existing routes: ```js router.addRoute({ path: '/about', name: 'about', component: About }) - // this will remove the previously added route because they have the same name and names are unique + // this will remove the previously added route because they have + // the same name and names are unique across all routes router.addRoute({ path: '/other', name: 'about', component: Other }) ``` diff --git a/packages/docs/guide/essentials/named-routes.md b/packages/docs/guide/essentials/named-routes.md index 5c329869..883c5dd7 100644 --- a/packages/docs/guide/essentials/named-routes.md +++ b/packages/docs/guide/essentials/named-routes.md @@ -39,3 +39,5 @@ router.push({ name: 'user', params: { username: 'erina' } }) In both cases, the router will navigate to the path `/user/erina`. Full example [here](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/router/src/types/index.ts b/packages/router/src/types/index.ts index 76588f71..e62e60db 100644 --- a/packages/router/src/types/index.ts +++ b/packages/router/src/types/index.ts @@ -246,7 +246,7 @@ export interface _RouteRecordBase extends PathParserOptions { alias?: string | string[] /** - * Name for the route record. + * Name for the route record. Must be unique. */ name?: RouteRecordName