Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在angular5的app.routes.ts中定义带有约束的路由(它应该包含一个字符串)_Angular_Angular5 - Fatal编程技术网

在angular5的app.routes.ts中定义带有约束的路由(它应该包含一个字符串)

在angular5的app.routes.ts中定义带有约束的路由(它应该包含一个字符串),angular,angular5,Angular,Angular5,当我的url包含“.vpf”时,我必须导航到一个组件。如何定义此app.routes.ts的路由 {path:':section',component:SectionBasedListingComponent}, 它将导航,而我给url喜欢 同样,当我的字符串包含.vpf时,我需要导航。我如何实现这一点 有人能帮我吗 谢谢您可以使用防护装置来实现这一点 @Injectable() export class AuthGuardService implements CanActivate {

当我的url包含“.vpf”时,我必须导航到一个组件。如何定义此app.routes.ts的路由

   {path:':section',component:SectionBasedListingComponent},
它将导航,而我给url喜欢

同样,当我的字符串包含.vpf时,我需要导航。我如何实现这一点

有人能帮我吗


谢谢

您可以使用防护装置来实现这一点

@Injectable()
export class AuthGuardService implements CanActivate {

  constructor(public router: Router) {}

 //check for parameter using ActivatedRoute or else

  //Navigate to this.router.navigate(['required path']);
}
检查它是如何在Authurads中完成的

{ path: 'profile', component: ProfileComponent, canActivate: [AuthGuard] },

您可以为此使用防护,检查字符串是否存在,并重定向到新路由,其中包含新组件:

 import { Injectable } from '@angular/core';
 import { CanActivate,ActivatedRouteSnapshot, RouterStateSnapshot } from 
    '@angular/router';

 import { AuthService } from './auth.service';

 @Injectable()
 export class CanActivateRouteGuard implements CanActivate {

 constructor(private auth: AuthService) {}

 canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): 
  boolean {
   if (state.url.indexOf('.vpf') !== -1) {
      this.router.navigate(['/yourNewRoute']);
    }
    return true;
  }
 }



{ path:':section',component:SectionBasedListingComponent , canActivate: [CanActivateRouteGuard ]},

分享更多详细信息谢谢,它不会影响我的authguard服务。我收到“无法匹配任何路线。URL段:'2018/01/25092736/Bus Tai.vpf”错误。我如何修复此错误