diff --git a/packages/router/src/lib/routes.spec.ts b/packages/router/src/lib/routes.spec.ts index 800a577a7..910e073ba 100644 --- a/packages/router/src/lib/routes.spec.ts +++ b/packages/router/src/lib/routes.spec.ts @@ -118,6 +118,49 @@ describe('routes', () => { }); }); + describe('a nested dynamic route', () => { + const files: Files = { + '/app/routes/categories.[categoryId].products.[productId].ts': () => + Promise.resolve({ default: RouteComponent }), + }; + + const routes = getRoutes(files); + const route: ModuleRoute = routes[0]; + + it('should have a path', () => { + expect(route.path).toBe('categories/:categoryId/products/:productId'); + }); + + it('should have a pathMatch set to prefix', () => { + expect(route.pathMatch).toBe('prefix'); + }); + + it('should have a _module property', () => { + expect(route._module).toBeDefined(); + + expect(typeof route._module).toBe('function'); + }); + + it('should have a loadChildren property', () => { + expect(route.loadChildren).toBeDefined(); + + expect(typeof route.loadChildren).toBe('function'); + }); + + it('should return an array of one route config from the loadChildren property', async () => { + expect(route.loadChildren).toBeDefined(); + + const routes = (await route.loadChildren()) as Route[]; + + expect(routes.length).toBe(1); + + const innerRoute = routes.shift(); + + expect(innerRoute.path).toBe(''); + expect(innerRoute.component).toBe(RouteComponent); + }); + }); + describe('an index route', () => { const files: Files = { '/app/routes/index.ts': () => diff --git a/packages/router/src/lib/routes.ts b/packages/router/src/lib/routes.ts index 0fdbfccac..35be51420 100644 --- a/packages/router/src/lib/routes.ts +++ b/packages/router/src/lib/routes.ts @@ -48,7 +48,9 @@ export function getRoutes( .filter(Boolean); segments.reduce((parent, segment, index) => { - const path = segment.replace(/index|^\(.*?\)$/g, '').replace('.', '/'); + const path = segment + .replace(/index|^\(.*?\)$/g, '') + .replace(/\./g, '/'); const isIndex = !path; const isCatchall = path === '**'; const pathMatch = isIndex ? 'full' : 'prefix';