fix(router): fix redirect to a URL with a param having multiple values (#16376)

fixes #16310

PR Close #16376
This commit is contained in:
Victor Berchet 2017-04-27 15:42:40 +02:00 committed by Miško Hevery
parent 415a0f8047
commit 5d4b36f80f
2 changed files with 18 additions and 1 deletions

View File

@ -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;
}

View File

@ -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(
[