From 23784a2eca11160a27d7af58e320d962f38649ec Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Fri, 30 Oct 2015 17:03:19 -0700 Subject: [PATCH] fix(router): properly serialize aux routes Previously, routes would be generated with a leading slash after the parens: example.com/foo(/bar) This fix removes the trailing slash when generating the URL, so now we have: example.com/foo(bar) This change is not breaking because we still recognize both forms. We just normalize without the slash. --- modules/angular2/src/router/instruction.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/angular2/src/router/instruction.ts b/modules/angular2/src/router/instruction.ts index 198c54c27d..492b22bfe5 100644 --- a/modules/angular2/src/router/instruction.ts +++ b/modules/angular2/src/router/instruction.ts @@ -137,7 +137,7 @@ export function stringifyInstruction(instruction: Instruction): string { export function stringifyInstructionPath(instruction: Instruction): string { return instruction.component.urlPath + stringifyAux(instruction) + - stringifyPrimary(instruction.child); + stringifyPrimaryPrefixed(instruction.child); } export function stringifyInstructionQuery(instruction: Instruction): string { @@ -146,6 +146,14 @@ export function stringifyInstructionQuery(instruction: Instruction): string { ''; } +function stringifyPrimaryPrefixed(instruction: Instruction): string { + var primary = stringifyPrimary(instruction); + if (primary.length > 0) { + primary = '/' + primary; + } + return primary; +} + function stringifyPrimary(instruction: Instruction): string { if (isBlank(instruction)) { return ''; @@ -153,8 +161,8 @@ function stringifyPrimary(instruction: Instruction): string { var params = instruction.component.urlParams.length > 0 ? (';' + instruction.component.urlParams.join(';')) : ''; - return '/' + instruction.component.urlPath + params + stringifyAux(instruction) + - stringifyPrimary(instruction.child); + return instruction.component.urlPath + params + stringifyAux(instruction) + + stringifyPrimaryPrefixed(instruction.child); } function stringifyAux(instruction: Instruction): string {