})
})
})
+
describe('Dynamic Routing', () => {
it('resolves new added routes', async () => {
const { router } = await newRouter()
})
})
+ it('checks if a route exists', async () => {
+ const { router } = await newRouter()
+ router.addRoute({
+ name: 'new-route',
+ path: '/new-route',
+ component: components.Foo,
+ })
+ expect(router.hasRoute('new-route')).toBe(true)
+ expect(router.hasRoute('no')).toBe(false)
+ router.removeRoute('new-route')
+ expect(router.hasRoute('new-route')).toBe(false)
+ })
+
it('can redirect to children in the middle of navigation', async () => {
const { router } = await newRouter()
expect(router.resolve('/new-route')).toMatchObject({
addRoute(parentName: RouteRecordName, route: RouteRecordRaw): () => void
addRoute(route: RouteRecordRaw): () => void
removeRoute(name: RouteRecordName): void
- // TODO: hasRoute()
+ hasRoute(name: RouteRecordName): boolean
getRoutes(): RouteRecord[]
resolve(to: RouteLocationRaw): RouteLocation
return matcher.getRoutes().map(routeMatcher => routeMatcher.record)
}
+ function hasRoute(name: RouteRecordName): boolean {
+ return !!matcher.getRecordMatcher(name)
+ }
+
function resolve(
location: RouteLocationRaw,
currentLocation?: RouteLocationNormalizedLoaded
addRoute,
removeRoute,
+ hasRoute,
getRoutes,
push,