})
})
+ it('throws when adding *', () => {
+ const matcher = createRouterMatcher([], {})
+ expect(() => {
+ matcher.addRoute({ path: '*', component })
+ }).toThrowError('Catch all')
+ })
+
+ it('does not throw when adding * in children', () => {
+ const matcher = createRouterMatcher([], {})
+ expect(() => {
+ matcher.addRoute({
+ path: '/something',
+ component,
+ children: [{ path: '*', component }],
+ })
+ }).not.toThrow()
+ })
+
it('adds children', () => {
const matcher = createRouterMatcher([], {})
matcher.addRoute({ path: '/parent', component, name: 'home' })
expect(tokenizePath('')).toEqual([[]])
})
+ it('not start with /', () => {
+ expect(() => tokenizePath('a')).toThrowError(`"a" should be "/a"`)
+ })
+
it('escapes :', () => {
expect(tokenizePath('/\\:')).toEqual([
[{ type: TokenType.Static, value: ':' }],
parent.record.path + (path && connectingSlash + path)
}
+ if (__DEV__ && normalizedRecord.path === '*') {
+ throw new Error(
+ 'Catch all routes ("*") must now be defined using a param with a custom regexp.\n' +
+ 'See more at https://next.router.vuejs.org/guide/migration/#removed-star-or-catch-all-routes.'
+ )
+ }
+
// create the object before hand so it can be passed to children
matcher = createRouteRecordMatcher(normalizedRecord, parent, options)
export function tokenizePath(path: string): Array<Token[]> {
if (!path) return [[]]
if (path === '/') return [[ROOT_TOKEN]]
+ // // v3 catchAll must be renew
+ // if (/^\/?\*/.test(path))
+ // throw new Error(
+ // `Catch all routes (/*) must now be defined using a parameter with a custom regex: /:catchAll(.*)`
+ // )
// remove the leading slash
- if (!path.startsWith('/'))
- throw new Error(`Route "${path}" should be "/${path}".`)
+ if (__DEV__ && !path.startsWith('/')) {
+ throw new Error(
+ `Route path should start with a "/": "${path}" should be "/${path}". This will break in production.`
+ )
+ path = '/' + path
+ }
// if (tokenCache.has(path)) return tokenCache.get(path)!