diff --git a/packages/kbn-typed-react-router-config/src/create_router.test.tsx b/packages/kbn-typed-react-router-config/src/create_router.test.tsx index d29079f37ec1..e0582de320a9 100644 --- a/packages/kbn-typed-react-router-config/src/create_router.test.tsx +++ b/packages/kbn-typed-react-router-config/src/create_router.test.tsx @@ -196,7 +196,15 @@ describe('createRouter', () => { it('throws an error if the given path does not match any routes', () => { expect(() => { router.getParams('/service-map', history.location); - }).toThrowError('No matching route found for /service-map'); + }).toThrowError('/service-map does not match current path /'); + + expect(() => { + router.getParams('/services/{serviceName}', history.location); + }).toThrowError('/services/{serviceName} does not match current path /'); + + expect(() => { + router.getParams('/service-map', '/services/{serviceName}', history.location); + }).toThrowError('None of /service-map, /services/{serviceName} match current path /'); }); it('does not throw an error if the given path does not match any routes but is marked as optional', () => { @@ -248,7 +256,7 @@ describe('createRouter', () => { expect(() => { router.matchRoutes('/traces', history.location); - }).toThrowError('No matching route found for /traces'); + }).toThrowError('/traces does not match current path /service-map'); }); it('applies defaults', () => { diff --git a/packages/kbn-typed-react-router-config/src/create_router.ts b/packages/kbn-typed-react-router-config/src/create_router.ts index 494540005224..f545fa8ed63e 100644 --- a/packages/kbn-typed-react-router-config/src/create_router.ts +++ b/packages/kbn-typed-react-router-config/src/create_router.ts @@ -99,7 +99,15 @@ export function createRouter(routes: TRoutes): Router< if (optional) { return []; } - throw new Error(`No matching route found for ${paths}`); + + let errorMessage: string; + + if (paths.length === 1) { + errorMessage = `${paths[0]} does not match current path ${location.pathname}`; + } else { + errorMessage = `None of ${paths.join(', ')} match current path ${location.pathname}`; + } + throw new Error(errorMessage); } return matches.slice(0, matchIndex + 1).map((matchedRoute) => {