).toHaveBeenWarned()
})
+ it('warns if a child with absolute path is missing a parent param', async () => {
+ createRouter({
+ history: createMemoryHistory(),
+ routes: [
+ {
+ path: '/:a',
+ component,
+ children: [
+ {
+ path: ':b',
+ component,
+ children: [{ path: '/:a/b', component }],
+ },
+ ],
+ },
+ ],
+ })
+ expect(
+ `Absolute path "/:a/b" should have the exact same param named "b" as its parent "/:a/:b".`
+ ).toHaveBeenWarned()
+ })
+
it('warns if an alias has a param with the same name but different', async () => {
createRouter({
history: createMemoryHistory(),
// create the object before hand so it can be passed to children
matcher = createRouteRecordMatcher(normalizedRecord, parent, options)
+ if (__DEV__ && parent && path[0] === '/')
+ checkMissingParamsInAbsolutePath(matcher, parent)
+
// if we are an alias we must tell the original record that we exist
// so we can be removed
if (originalRecord) {
}
}
+function checkMissingParamsInAbsolutePath(
+ record: RouteRecordMatcher,
+ parent: RouteRecordMatcher
+) {
+ for (let key of parent.keys) {
+ if (!record.keys.find(isSameParam.bind(null, key)))
+ return warn(
+ `Absolute path "${record.record.path}" should have the exact same param named "${key.name}" as its parent "${parent.record.path}".`
+ )
+ }
+}
+
export { PathParserOptions, _PathParserOptions }