如何检查守卫中的skipLocationChange?

时间:2018-06-29 09:52:16

标签: angular angular6

我有一些路线,这些路线不能直接通过url调用,而应该可以通过angular导航。
到目前为止,我在angular中使用了skipLocationChange来调用路由,并在组件上添加了一些逻辑以检查url是否与component-url相同,如果是,则重定向到错误页面。

示例(元)代码

// Inside routing module
{
  path: 'example_component',
  component: ExampleComponent
}

// Inside example component
ngOnInit() {
  if (currentPath.includes('example_component')) {
    navigateToError();
  }
}

// Inside some other component
goToExampleComponent() {
  this.router.navigate(['/example_component'], { skipLocationChange: true}]);
}

我想知道我是否可以通过守卫实现相同的行为,如果可以,怎么办?

0 个答案:

没有答案