There are few different ways to remove existing routes:
- By adding a route with a conflicting name. If you add a route that has the same name as an existing route, it will remove the route first and then add the route:
+
```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
router.addRoute({ path: '/other', name: 'about', component: Other })
```
+
- By calling the callback returned by `router.addRoute()`:
+
```js
const removeRoute = router.addRoute(routeRecord)
removeRoute() // removes the route if it exists
```
+
This is useful when the routes do not have a name
- By using `router.removeRoute()` to remove a route by its name:
+
```js
router.addRoute({ path: '/about', name: 'about', component: About })
// remove the route
router.removeRoute('about')
```
+
Note you can use `Symbol`s for names in routes if you wish to use this function but want to avoid conflicts in names.
Whenever a route is removed, **all of its aliases and children** are removed with it.
Vue Router gives you two functions to look at existing routes:
-- [`router.hasRoute()`](../../api/interfaces/router.html#Methods-hasRoute): check if a route exists
-- [`router.getRoutes()`](../../api/interfaces/Router.html#Methods-getRoutes): get an array with all the route records.
+- [`router.hasRoute()`](/api/interfaces/Router.md#Methods-hasRoute): check if a route exists
+- [`router.getRoutes()`](/api/interfaces/Router.md#Methods-getRoutes): get an array with all the route records.
### Apache
-```apacheconf
+```
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
### Removal of `router.match` and changes to `router.resolve`
-Both `router.match`, and `router.resolve` have been merged together into `router.resolve` with a slightly different signature. [Refer to the API](api/interfaces/router#Methods-resolve) for more details.
+Both `router.match`, and `router.resolve` have been merged together into `router.resolve` with a slightly different signature. [Refer to the API](/api/interfaces/Router.md#Methods-resolve) for more details.
**Reason**: Uniting multiple methods that were used for the same purpose.
Decoded values in `params`, `query`, and `hash` are now consistent no matter where the navigation is initiated (older browsers will still produce unencoded `path` and `fullPath`). The initial navigation should yield the same results as in-app navigations.
-Given any [normalized route location](../../api/#routelocationnormalized):
+Given any [normalized route location](/api/interfaces/RouteLocationNormalized.md):
- Values in `path`, `fullPath` are not decoded anymore. They will appear as provided by the browser (most browsers provide them encoded). e.g. directly writing on the address bar `https://example.com/hello world` will yield the encoded version: `https://example.com/hello%20world` and both `path` and `fullPath` will be `/hello%20world`.
-- `hash` is now decoded, that way it can be copied over: `router.push({ hash: $route.hash })` and be used directly in [scrollBehavior](../../api/#scrollbehavior)'s `el` option.
+- `hash` is now decoded, that way it can be copied over: `router.push({ hash: $route.hash })` and be used directly in [scrollBehavior](/api/interfaces/RouterOptions.md#Properties-scrollBehavior)'s `el` option.
- When using `push`, `resolve`, and `replace` and providing a `string` location or a `path` property in an object, **it must be encoded** (like in the previous version). On the other hand, `params`, `query` and `hash` must be provided in its unencoded version.
- The slash character (`/`) is now properly decoded inside `params` while still producing an encoded version on the URL: `%2F`.
### Apache
-```apacheconf
+```
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
### 删除 `router.match` 改为 `router.resolve`
-`router.match` 和 `router.resolve` 已合并到 `router.resolve` 中,签名略有不同。[详见 API](../../api/interfaces/router#Methods-resolve)。
+`router.match` 和 `router.resolve` 已合并到 `router.resolve` 中,签名略有不同。[详见 API](/api/interfaces/Router#Methods-resolve)。
**原因**:将用于同一目的的多种方法统一起来。
无论在哪里启动导航,`params`、`query`和 `hash` 中的解码值现在都是一致的(旧的浏览器仍然会产生未编码的 `path` 和 `fullPath`)。初始导航应产生与应用内部导航相同的结果。
-给定任何[规范化的路由地址](../../api/#routelocationnormalized):
+<!-- TODO: translate chinese API entries -->
-- `path`, `fullPath`中的值不再被解码了。例如,直接在地址栏上写 "https://example.com/hello world",将得到编码后的版本:"https://example.com/hello%20world",而 "path "和 "fullPath "都是"/hello%20world"。
-- `hash` 现在被解码了,这样就可以复制过来。`router.push({ hash: $route.hash })` 可以直接用于 [scrollBehavior](../../api/#scrollbehavior) 的 `el` 配置中。
+给定任何[规范化的路由地址](/api/interfaces/RouteLocationNormalized.md):
+
+- `path`, `fullPath`中的值不再被解码了。例如,直接在地址栏上写 "<https://example.com/hello> world",将得到编码后的版本:"https://example.com/hello%20world",而 "path "和 "fullPath "都是"/hello%20world"。
+- `hash` 现在被解码了,这样就可以复制过来。`router.push({ hash: $route.hash })` 可以直接用于 [scrollBehavior](/api/interfaces/RouterOptions.md#Properties-scrollBehavior) 的 `el` 配置中。
- 当使用 `push`、`resolve` 和 `replace` 并在对象中提供 `string` 地址或 `path` 属性时,**必须进行编码**(像以前的版本一样)。另一方面,`params`、`query` 和 `hash` 必须以未编码的版本提供。
- 斜线字符(`/`)现在已在 `params` 内正确解码,同时仍在 URL 上产生一个编码版本:`%2F`。