const matcher = new RouterMatcher(record)
const targetLocation = {}
+ if (!('meta' in resolved)) {
+ resolved.meta = record[0].meta || {}
+ }
+
// add location if provided as it should be the same value
if ('path' in location) {
resolved.path = location.path
expect(
assertErrorMatch({ path: '/', component }, { path: '/foo' })
).toMatchInlineSnapshot(
- `[NoRouteMatchError: No match for {"path":"/foo","params":{},"query":{},"hash":"","fullPath":"/","meta":{}}]`
+ `[NoRouteMatchError: No match for {"path":"/foo","params":{},"query":{},"hash":"","fullPath":"/"}]`
)
})
})
expect(
assertErrorMatch({ path: '/', component }, { name: 'Home' })
).toMatchInlineSnapshot(
- `[NoRouteMatchError: No match for {"path":"/","name":"Home","params":{},"query":{},"hash":"","fullPath":"/","meta":{}}]`
+ `[NoRouteMatchError: No match for {"path":"/","name":"Home","params":{},"query":{},"hash":"","fullPath":"/"}]`
)
})
})
params: {},
path: '/home',
matched: [record],
+ meta: {},
}
)
})
name: undefined,
params: { id: 'ed', role: 'user' },
matched: [record],
+ meta: {},
}
)
})
name: 'UserEdit',
params: { id: 'ed', role: 'user' },
matched: [],
+ meta: {},
}
)
})
name: 'UserEdit',
params: { id: 'ed', role: 'user' },
matched: [record],
+ meta: {},
}
)
})
name: undefined,
params: { id: 'ed', role: 'user' },
matched: [record],
+ meta: {},
}
)
})
params: {},
name: undefined,
matched: [],
+ meta: {},
},
}
)
params: {},
name: undefined,
matched: [],
+ meta: {},
},
}
)
params: {},
name: undefined,
matched: [],
+ meta: {},
},
}
)
params: {},
name: undefined,
matched: [],
+ meta: {},
},
}
)
params: {},
name: 'redirect',
matched: [],
+ meta: {},
},
}
)
assertErrorMatch(
{ path: '/redirect', redirect: '/home' },
{ params: {} },
- { path: '/redirect', params: {}, matched: [], name: undefined }
+ {
+ path: '/redirect',
+ params: {},
+ matched: [],
+ name: undefined,
+ meta: {},
+ }
)
).toMatchInlineSnapshot(`
- [InvalidRouteMatch: Cannot redirect using a relative location:
- {
- "params": {}
- }
- Use the function redirect and explicitely provide a name]
- `)
+ [InvalidRouteMatch: Cannot redirect using a relative location:
+ {
+ "params": {}
+ }
+ Use the function redirect and explicitely provide a name]
+ `)
})
it('normalize a location when redirecting', () => {
params: { a: 'foo' },
name: 'a',
matched: [],
+ meta: {},
},
}
)
assertErrorMatch(
record,
{},
- { ...start, matched: start.matched.map(normalizeRouteRecord) }
+ {
+ ...start,
+ matched: start.matched.map(normalizeRouteRecord),
+ meta: {},
+ }
)
).toMatchInlineSnapshot(
`[NoRouteMatchError: No match for {"name":"home","params":{},"path":"/"}]`
matched: [],
params: {},
path: '/foo/nested/a',
+ meta: {},
}
)
})
-import { RouteLocationNormalized, RouteLocation } from './types'
+import {
+ RouteLocationNormalized,
+ RouteLocation,
+ MatcherLocationNormalized,
+ MatcherLocation,
+} from './types'
// we could use symbols, but this is for IE9 only and there is
// not Symbol support anyway
// @ts-ignore for IE inheritance support
private [isNoRouteMatchError] = true
- constructor(currentLocation: any, location: any) {
+ constructor(
+ currentLocation: MatcherLocationNormalized,
+ location: MatcherLocation
+ ) {
// TODO: change the merge to provide information that is useful only
- super('No match for ' + JSON.stringify({ ...currentLocation, ...location }))
+ super(
+ 'No match for ' +
+ JSON.stringify(mergeMatcherLocations(currentLocation, location))
+ )
}
static is(error: Error): error is NoRouteMatchError {
}
return JSON.stringify(location, null, 2)
}
+
+function mergeMatcherLocations(
+ currentLocation: MatcherLocationNormalized,
+ location: MatcherLocation
+) {
+ const merged = { ...currentLocation, ...location }
+ delete merged.meta
+ return merged
+}