history,
routes: [{ path: '/:p', name: 'p', component }],
})
- router.resolve({ path: '/', params: { p: 'p' } })
- expect('Path "/" was passed with params').toHaveBeenWarned()
+ router.resolve({ path: '/p', params: { p: 'p' } })
+ expect('Path "/p" was passed with params').toHaveBeenWarned()
})
it('does not warn when resolving a route with path, params and name', async () => {
it('should warn if multiple leading slashes with raw location', async () => {
const router = createRouter({
history: createMemoryHistory(),
- routes: [{ path: '/foo', component }],
+ routes: [{ path: '/', component }],
})
await expect(router.push('//not-valid')).resolves.toBe(undefined)
it('should warn if multiple leading slashes with object location', async () => {
const router = createRouter({
history: createMemoryHistory(),
- routes: [{ path: '/foo', component }],
+ routes: [{ path: '/', component }],
})
await expect(router.push({ path: '//not-valid' })).resolves.toBe(undefined)
await expect(router.push({ path: '/foo' })).resolves.toBe(undefined)
expect('"/foo" is a Promise instead of a function').toHaveBeenWarned()
})
+
+ it('warns if no route matched', async () => {
+ const router = createRouter({
+ history: createMemoryHistory(),
+ routes: [{ path: '/', name: 'a', component }],
+ })
+
+ await expect(router.push('/foo')).resolves.toBe(undefined)
+ expect(`No match found for location with path "/foo"`).toHaveBeenWarned()
+
+ await expect(router.push({ path: '/foo2' })).resolves.toBe(undefined)
+ expect(`No match found for location with path "/foo2"`).toHaveBeenWarned()
+ })
})
warn(
`Location "${rawLocation}" resolved to "${href}". A resolved location cannot start with multiple slashes.`
)
+ else if (!matchedRoute.matched.length) {
+ warn(`No match found for location with path "${rawLocation}"`)
+ }
}
return {
}
let matchedRoute = matcher.resolve(matcherLocation, currentLocation)
-
const hash = encodeHash(rawLocation.hash || '')
if (__DEV__ && hash && hash[0] !== '#') {
warn(
`Location "${rawLocation}" resolved to "${href}". A resolved location cannot start with multiple slashes.`
)
+ else if (!matchedRoute.matched.length) {
+ warn(
+ `No match found for location with path "${
+ 'path' in rawLocation ? rawLocation.path : rawLocation
+ }"`
+ )
+ }
}
return {