})
})
+ it('can remove all records', () => {
+ const matcher = createRouterMatcher([], {})
+ matcher.addRoute({ path: '/', component })
+ matcher.addRoute({ path: '/about', component, name: 'about' })
+ matcher.addRoute({
+ path: '/with-children',
+ component,
+ children: [{ path: 'child', component }],
+ })
+ expect(matcher.getRoutes()).not.toHaveLength(0)
+ matcher.clearRoutes()
+ expect(matcher.getRoutes()).toHaveLength(0)
+ expect(matcher.getRecordMatcher('about')).toBeFalsy()
+ })
+
it('throws when adding *', () => {
const matcher = createRouterMatcher([], {})
expect(() => {
*/
export interface RouterMatcher {
addRoute: (record: RouteRecordRaw, parent?: RouteRecordMatcher) => () => void
-
removeRoute(matcher: RouteRecordMatcher): void
removeRoute(name: NonNullable<RouteRecordNameGeneric>): void
-
+ clearRoutes: () => void
getRoutes: () => RouteRecordMatcher[]
getRecordMatcher: (
name: NonNullable<RouteRecordNameGeneric>
// add initial routes
routes.forEach(route => addRoute(route))
- return { addRoute, resolve, removeRoute, getRoutes, getRecordMatcher }
+ function clearRoutes() {
+ matchers.length = 0
+ matcherMap.clear()
+ }
+
+ return {
+ addRoute,
+ resolve,
+ removeRoute,
+ clearRoutes,
+ getRoutes,
+ getRecordMatcher,
+ }
}
function paramsFromLocation(
*/
getRoutes(): RouteRecord[]
+ /**
+ * Delete all routes from the router matcher.
+ */
+ clearRoutes(): void
+
/**
* Returns the {@link RouteLocation | normalized version} of a
* {@link RouteLocationRaw | route location}. Also includes an `href` property
addRoute,
removeRoute,
+ clearRoutes: matcher.clearRoutes,
hasRoute,
getRoutes,
resolve,