history,
routes: [{ path: '/:p', name: 'p', component }],
})
+ // @ts-expect-error: cannot pass params with a path
router.push({ path: '/p', params: { p: 'p' } })
expect('Path "/p" was passed with params').toHaveBeenWarned()
})
history,
routes: [{ path: '/:p', name: 'p', component }],
})
+ // @ts-expect-error: it would be better if this didn't error but it still an
+ // invalid location
router.push({ path: '/p', name: 'p', params: { p: 'p' } })
expect('Path "/" was passed with params').not.toHaveBeenWarned()
})
function stringifyRoute(to: RouteLocationRaw): string {
if (typeof to === 'string') return to
- if ('path' in to) return to.path
+ if (to.path != null) return to.path
const location = {} as Record<string, unknown>
for (const key of propertiesToLog) {
if (key in to) location[key] = to[key]
)
// throws if cannot be stringified
path = matcher.stringify(params)
- } else if ('path' in location && location.path != null) {
+ } else if (location.path != null) {
// no need to resolve the path with the matcher as it was provided
// this also allows the user to control the encoding
path = location.path
let matcherLocation: MatcherLocationRaw
// path could be relative in object as well
- if ('path' in rawLocation && rawLocation.path != null) {
+ if (rawLocation.path != null) {
if (
__DEV__ &&
'params' in rawLocation &&
} else if (!matchedRoute.matched.length) {
warn(
`No match found for location with path "${
- 'path' in rawLocation ? rawLocation.path : rawLocation
+ rawLocation.path != null ? rawLocation.path : rawLocation
}"`
)
}
if (
__DEV__ &&
- !('path' in newTargetLocation) &&
+ newTargetLocation.path == null &&
!('name' in newTargetLocation)
) {
warn(
query: to.query,
hash: to.hash,
// avoid transferring params if the redirect has a path
- params: 'path' in newTargetLocation ? {} : to.params,
+ params: newTargetLocation.path != null ? {} : to.params,
},
newTargetLocation
)
*/
export interface MatcherLocationAsName {
name: RouteRecordName
+ // to allow checking location.path == null
+ path?: undefined
params?: RouteParams
}
* @internal
*/
export interface MatcherLocationAsRelative {
+ // to allow checking location.path == null
+ path?: undefined
params?: RouteParams
}
*/
export interface LocationAsRelativeRaw {
name?: RouteRecordName
+ // to allow checking location.path == null
+ path?: undefined
params?: RouteParamsRaw
}