Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/test/bundling/router/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@
{
"name": "createTemplateRef"
},
{
"name": "createUrlTree"
},
{
"name": "deactivateRouteAndItsChildren"
},
Expand Down
15 changes: 14 additions & 1 deletion packages/router/src/create_url_tree_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@ export class LegacyCreateUrlTree implements CreateUrlTreeStrategy {
relativeTo: ActivatedRoute|null|undefined, currentState: RouterState, currentUrlTree: UrlTree,
commands: any[], queryParams: Params|null, fragment: string|null): UrlTree {
const a = relativeTo || currentState.root;
return createUrlTree(a, currentUrlTree, commands, queryParams, fragment);
const tree = createUrlTree(a, currentUrlTree, commands, queryParams, fragment);
if (NG_DEV_MODE) {
const treeFromSnapshotStrategy = new CreateUrlTreeUsingSnapshot().createUrlTree(
relativeTo, currentState, currentUrlTree, commands, queryParams, fragment);
if (treeFromSnapshotStrategy.toString() !== tree.toString()) {
let warningString = `The navigation to ${tree.toString()} will instead go to ${
treeFromSnapshotStrategy.toString()} in an upcoming version of Angular.`;
if (!!relativeTo) {
warningString += ' `relativeTo` might need to be removed from the `UrlCreationOptions`.';
}
tree._warnIfUsedForNavigation = warningString;
}
}
return tree;
}
}

Expand Down
12 changes: 8 additions & 4 deletions packages/router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,14 @@ export class Router {
navigateByUrl(url: string|UrlTree, extras: NavigationBehaviorOptions = {
skipLocationChange: false
}): Promise<boolean> {
if (typeof ngDevMode === 'undefined' ||
ngDevMode && this.isNgZoneEnabled && !NgZone.isInAngularZone()) {
this.console.warn(
`Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?`);
if (NG_DEV_MODE) {
if (this.isNgZoneEnabled && !NgZone.isInAngularZone()) {
this.console.warn(
`Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?`);
}
if (url instanceof UrlTree && url._warnIfUsedForNavigation) {
this.console.warn(url._warnIfUsedForNavigation);
}
}

const urlTree = isUrlTree(url) ? url : this.parseUrl(url);
Expand Down
2 changes: 2 additions & 0 deletions packages/router/src/url_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ function matrixParamsMatch(
export class UrlTree {
/** @internal */
_queryParamMap?: ParamMap;
/** @internal */
_warnIfUsedForNavigation?: string;

constructor(
/** The root segment group of the URL tree */
Expand Down