【问题标题】:How to Get Piece of Path in Angular [duplicate]如何在Angular中获取一条路径[重复]
【发布时间】:2019-02-09 00:01:01
【问题描述】:

我想在GetTokenKeyGuard.ts 文件中获取tokenKey 片段ActivatedRouteSnapshot

我试过这样但不起作用:

canActivate(route: ActivatedRouteSnapshot) {

    localStorage.setItem('token_key', route.queryParams.tokenKey);

    return true;
  }

因为 tokenKey 不是查询参数(不是localhost/path?tokenKey=blabla)。

const routes: Routes = [
  { path: '', component: IndexComponent },
  { path: 'auth/login', component: LoginComponent },
  { path: 'auth/login/:tokenKey', canActivate: [GetTokenKeyGuard], component: LoginComponent },
];

如何获取GetTokenKey.ts中路径的tokenKey变量?

【问题讨论】:

    标签: javascript angular typescript


    【解决方案1】:

    我找到了:

    不是queryParams。只有params

    localStorage.setItem('token_key', route.params.tokenKey);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-14
      • 2013-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-25
      • 1970-01-01
      相关资源
      最近更新 更多