Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0bd22da

Browse filesBrowse files
committed
fix(@angular/ssr): replace all route parameters when resolving relative redirects
When resolving a relative `redirectTo` property for a route with multiple path parameters (e.g. `:param1/:param2`), only the first parameter segment was being converted to `*` because a non-global regular expression was used. This commit updates `resolveRedirectTo` to use `URL_PARAMETER_GLOBAL_REGEXP` so that all parameter placeholders in the route path are properly replaced with `*`. Fixes #33504
1 parent 34d558c commit 0bd22da
Copy full SHA for 0bd22da

2 files changed

+30-1Lines changed: 30 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/angular/ssr/src/routes/ng-routes.ts‎

Copy file name to clipboardExpand all lines: packages/angular/ssr/src/routes/ng-routes.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ function resolveRedirectTo(routePath: string, redirectTo: string): string {
547547
}
548548

549549
// Resolve relative redirectTo based on the current route path.
550-
const segments = routePath.replace(URL_PARAMETER_REGEXP, '*').split('/');
550+
const segments = routePath.replace(URL_PARAMETER_GLOBAL_REGEXP, '*').split('/');
551551
segments.pop(); // Remove the last segment to make it relative.
552552

553553
return joinUrlParts(...segments, redirectTo);
Collapse file

‎packages/angular/ssr/test/routes/ng-routes_spec.ts‎

Copy file name to clipboardExpand all lines: packages/angular/ssr/test/routes/ng-routes_spec.ts
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,35 @@ describe('extractRoutesAndCreateRouteTree', () => {
502502
]);
503503
});
504504

505+
it('should extract nested redirects with multiple path parameters', async () => {
506+
setAngularAppTestingManifest(
507+
[
508+
{
509+
path: ':param1/:param2',
510+
children: [
511+
{
512+
path: '',
513+
pathMatch: 'full',
514+
redirectTo: 'thing',
515+
},
516+
{
517+
path: 'thing',
518+
component: DummyComponent,
519+
},
520+
],
521+
},
522+
],
523+
[{ path: '**', renderMode: RenderMode.Server }],
524+
);
525+
526+
const { routeTree, errors } = await extractRoutesAndCreateRouteTree({ url });
527+
expect(errors).toHaveSize(0);
528+
expect(routeTree.toObject()).toEqual([
529+
{ route: '/*/*', renderMode: RenderMode.Server, redirectTo: '/*/*/thing' },
530+
{ route: '/*/*/thing', renderMode: RenderMode.Server },
531+
]);
532+
});
533+
505534
it('should not resolve parameterized routes for SSG when `invokeGetPrerenderParams` is false', async () => {
506535
setAngularAppTestingManifest(
507536
[

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.