Converts a `UrlTree` into a url
(tree: UrlTree)
| 453 | |
| 454 | /** Converts a `UrlTree` into a url */ |
| 455 | serialize(tree: UrlTree): string { |
| 456 | const segment = `/${serializeSegment(tree.root, true)}`; |
| 457 | if (segment.startsWith('//')) { |
| 458 | throw new RuntimeError( |
| 459 | RuntimeErrorCode.PROTOCOL_RELATIVE_URL_NOT_ALLOWED, |
| 460 | (typeof ngDevMode === 'undefined' || ngDevMode) && |
| 461 | 'Cannot serialize a UrlTree that would produce a protocol-relative URL.', |
| 462 | ); |
| 463 | } |
| 464 | const query = serializeQueryParams(tree.queryParams); |
| 465 | const fragment = |
| 466 | typeof tree.fragment === `string` ? `#${encodeUriFragment(tree.fragment)}` : ''; |
| 467 | |
| 468 | return `${segment}${query}${fragment}`; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | const DEFAULT_SERIALIZER = new DefaultUrlSerializer(); |