Skip to content

Commit

Permalink
fix(router): fix redirect to a URL with a param having multiple values (
Browse files Browse the repository at this point in the history
#16376)

fixes #16310

PR Close #16376
  • Loading branch information
vicb authored and mhevery committed May 8, 2017
1 parent 415a0f8 commit 5d4b36f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/router/src/apply_redirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions packages/router/test/apply_redirects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down

0 comments on commit 5d4b36f

Please sign in to comment.