// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`Router Matcher resolve LocationAsName throws if the named route does not exists 1`] = `[NoRouteMatchError: No match for {"path":"/","name":"Home","params":{},"query":{},"hash":"","fullPath":"/"}]`;
+exports[`Router Matcher resolve LocationAsName throws if the named route does not exists 1`] = `
+[NoRouteMatchError: No match for
+{"name":"Home"}]
+`;
-exports[`Router Matcher resolve LocationAsPath throws if the path does not exists 1`] = `[NoRouteMatchError: No match for {"path":"/foo","params":{},"query":{},"hash":"","fullPath":"/"}]`;
+exports[`Router Matcher resolve LocationAsPath disallows multiple trailing slashes 1`] = `
+[NoRouteMatchError: No match for
+{"path":"/home//"}]
+`;
+
+exports[`Router Matcher resolve LocationAsPath throws if the path does not exists 1`] = `
+[NoRouteMatchError: No match for
+{"path":"/foo"}]
+`;
exports[`Router Matcher resolve LocationAsRelative redirects throws if relative location when redirecting 1`] = `
[InvalidRouteMatch: Cannot redirect using a relative location:
Use the function redirect and explicitely provide a name]
`;
-exports[`Router Matcher resolve LocationAsRelative throws if the current named route does not exists 1`] = `[NoRouteMatchError: No match for {"name":"home","params":{},"path":"/"}]`;
+exports[`Router Matcher resolve LocationAsRelative throws if the current named route does not exists 1`] = `
+[NoRouteMatchError: No match for
+{"params":{"a":"foo"}}
+while being at
+{"name":"home","params":{},"path":"/","meta":{}}]
+`;
expect(
assertErrorMatch(
record,
- {},
+ { params: { a: 'foo' } },
{
...start,
matched: start.matched.map(normalizeRouteRecord),
private [isNoRouteMatchError] = true
constructor(
- currentLocation: MatcherLocationNormalized,
- location: MatcherLocation
+ location: MatcherLocation,
+ currentLocation?: MatcherLocationNormalized
) {
- // TODO: change the merge to provide information that is useful only
super(
- 'No match for ' +
- JSON.stringify(mergeMatcherLocations(currentLocation, location))
+ 'No match for\n' +
+ JSON.stringify(location) +
+ (currentLocation
+ ? '\nwhile being at\n' + JSON.stringify(currentLocation)
+ : '')
)
}
}
return JSON.stringify(location, null, 2)
}
-
-function mergeMatcherLocations(
- currentLocation: MatcherLocationNormalized,
- location: MatcherLocation
-) {
- const merged = { ...currentLocation, ...location }
- delete merged.meta
- return merged
-}
if ('name' in location && location.name) {
matcher = matchers.find(m => m.record.name === location.name)
- if (!matcher) throw new NoRouteMatchError(currentLocation, location)
+ if (!matcher) throw new NoRouteMatchError(location)
name = matcher.record.name
// TODO: merge params
// TODO: if no matcher, return the location with an empty matched array
// to allow non existent matches
// TODO: warning of unused params if provided
- if (!matcher) throw new NoRouteMatchError(currentLocation, location)
+ if (!matcher) throw new NoRouteMatchError(location)
// no need to resolve the path with the matcher as it was provided
// this also allows the user to control the encoding
matcher = currentLocation.name
? matchers.find(m => m.record.name === currentLocation.name)
: matchers.find(m => m.re.test(currentLocation.path))
- if (!matcher) throw new NoRouteMatchError(currentLocation, location)
+ if (!matcher) throw new NoRouteMatchError(location, currentLocation)
name = matcher.record.name
params = location.params || currentLocation.params
path = matcher.resolve(params)