diff --git a/packages/router/src/apply_redirects.ts b/packages/router/src/apply_redirects.ts index 8af1df37c9..8000df3368 100644 --- a/packages/router/src/apply_redirects.ts +++ b/packages/router/src/apply_redirects.ts @@ -358,7 +358,13 @@ class ApplyRedirects { private createQueryParams(redirectToParams: Params, actualParams: Params): Params { const res: Params = {}; forEach(redirectToParams, (v: any, k: string) => { - res[k] = v.startsWith(':') ? actualParams[v.substring(1)] : v; + const copySourceValue = typeof v === 'string' && v.startsWith(':'); + if (copySourceValue) { + const sourceName = v.substring(1); + res[k] = actualParams[sourceName]; + } else { + res[k] = v; + } }); return res; } diff --git a/packages/router/test/apply_redirects.spec.ts b/packages/router/test/apply_redirects.spec.ts index 9c194c3a00..82ca451824 100644 --- a/packages/router/test/apply_redirects.spec.ts +++ b/packages/router/test/apply_redirects.spec.ts @@ -41,6 +41,17 @@ describe('applyRedirects', () => { (t: UrlTree) => { expectTreeToBe(t, '/a/b/c'); }); }); + it('should support redirecting with to an URL with query parameters', () => { + const config: Routes = [ + {path: 'single_value', redirectTo: '/dst?k=v1'}, + {path: 'multiple_values', redirectTo: '/dst?k=v1&k=v2'}, + {path: '**', component: ComponentA}, + ]; + + checkRedirect(config, 'single_value', (t: UrlTree) => expectTreeToBe(t, '/dst?k=v1')); + checkRedirect(config, 'multiple_values', (t: UrlTree) => expectTreeToBe(t, '/dst?k=v1&k=v2')); + }); + it('should handle positional parameters', () => { checkRedirect( [