fix(router): throw an error when navigate to null/undefined path
Closes #10560 Fixes #13384
This commit is contained in:

committed by
Matias Niemelä

parent
8c7e93bebe
commit
46cb04d575
@ -526,6 +526,7 @@ export class Router {
|
||||
*/
|
||||
navigate(commands: any[], extras: NavigationExtras = {skipLocationChange: false}):
|
||||
Promise<boolean> {
|
||||
validateCommands(commands);
|
||||
if (typeof extras.queryParams === 'object' && extras.queryParams !== null) {
|
||||
extras.queryParams = this.removeEmptyProps(extras.queryParams);
|
||||
}
|
||||
@ -1238,3 +1239,12 @@ function getOutlet(outletMap: RouterOutletMap, route: ActivatedRoute): RouterOut
|
||||
}
|
||||
return outlet;
|
||||
}
|
||||
|
||||
function validateCommands(commands: string[]): void {
|
||||
for (let i = 0; i < commands.length; i++) {
|
||||
const cmd = commands[i];
|
||||
if (cmd == null) {
|
||||
throw new Error(`The requested path contains ${cmd} segment at index ${i}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user