路线参数不适用于警卫

时间:2017-08-25 15:01:19

标签: javascript angular angular-routing angular-router angular-router-guards

为什么以下警卫没有id可用?

@Injectable()
export class ProjectDetailsGuard implements CanActivate {

    constructor(private activatedRoute: ActivatedRoute) { }

    canActivate() {
        const id = this.activatedRoute.snapshot.params['id'];

        console.log(id); // <-- undefined
    }

}

在组件内部实现时,相同的代码可以正常工作。

1 个答案:

答案 0 :(得分:4)

ActivatedRoute只有在激活路线后才能提供参数。如果需要在params被激活之前获得canActivate,请ActivatedRouteSnapshot方法尝试使用canActivate(activatedRoute: ActivatedRouteSnapshot) { const id = activatedRoute.params['id']; console.log(id); }

MyDataset <- RxXdfData("./path/dataset.xdf") #the dataset you are using

# replace transFormedCol with the name of the col you want to use 
rxDataStep(inData = MyDataset,
           outFile = MyDataset,
           transforms = list(
             transFormedCol = ifelse(col1 == '1',col2*0.5,
                                     ifelse(col2 == '2', col2*0.8))), #etc...
           overwrite = TRUE
           )