另外:[ng] 错误:无法读取未定义的 'loadChildren' 属性 [ng] i 「wdm」: 编译失败。
app.routing.module.tsapp-routing.module.ts:21 抛出类型错误:无法读取未定义的 'getLandingPage' 属性 at Module../src/app/app-routing.module.ts (app-routing.module.ts:21) at webpack_require (bootstrap:83) at Module../src/app/app.module.ts (app.component.ts:21) at webpack_require (bootstrap:83) at Module../src/main.ts (main.ts:1) at webpack_require (bootstrap:83) at Object.0 (main.ts:13) at webpack_require (bootstrap:83) at checkDeferredModules (bootstrap:45) at Array.webpackJsonpCallback [as push] (bootstrap:32)
const routes: Routes = [
{
path: "",
redirectTo: this.getLandingPage(), // here is the issue
pathMatch: "full",
},
{
path: "tabs",
loadChildren: "./pages/tabs/tabs.module#TabsPageModule",
},
{
path: 'landing',
loadChildren: './pages/landing/landing.module#LandingPageModule'
},
];
export class AppRoutingModule {
getLandingPage(): string {
let url = "";
switch (environment.hotelName) {
case "h1":
url = "tabs";
break;
case "h2":
url = "landing";
break;
default:
}
return url;
}
}
我有一个如下所示的 auth.gurad.ts
文件。我不确定在哪里可以使用它。
export class AuthGuard implements CanActivate {
constructor(private router: Router,
private user: UserService,
private localStorageService: LocalStorageService) { }
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
return new Promise(async resolve => {
const userInfo: UserInfo = await this.localStorageService.get(LocalStorage.USER_INFO);
if (userInfo && (moment() < moment(userInfo.expireDate))) {
this.user.guest = false;
return resolve(true);
}
this.user.guest = true;
this.router.navigate(["/sign-in"]);
return resolve(false);
});
}
}