Angular 8-它如何确定启动页面

问题描述 投票:0回答:2

我有一个在启动时显示登录页面的Angular 8应用程序。

如何/如何将其设置为启动页面?路由模块只有1个,我到处都在寻找它的引用,但没有任何东西指示该页面在启动时应该显示。

我想念的是什么?有什么想法吗?

enter image description here

这是app-routing.module.ts文件:

import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {HomeComponent} from './pages/home/home.component';
import {DetailsComponent} from './pages/details/details.component';
import {AddComponent} from './pages/add/add.component';
import {LoginComponent} from './pages/login/login.component';
import {SignupComponent} from './pages/signup/signup.component';

import {AuthGuard} from './guards/auth.guard';
import {AppGuard} from './guards/app.guard';

const routes: Routes = [
   {path: '', component: HomeComponent, canActivate: [AppGuard]},
   {path: 'details/:city', component: DetailsComponent, canActivate: [AppGuard]},
   {path: 'add', component: AddComponent, canActivate: [AppGuard]},
   {path: 'login', component: LoginComponent, canActivate: [AuthGuard]},
   {path: 'signup', component: SignupComponent , canActivate: [AuthGuard]},
   {path: '**', redirectTo: ''}
];

@NgModule({
 imports: [RouterModule.forRoot(routes)],
 exports: [RouterModule]
})
export class AppRoutingModule {}
angular
2个回答
0
投票

[如果您查看代码,则会得到Routes数组,该数组显示将基于URL或所采用的导航路径呈现的组件。现在,如果您将看到canActivate属性,则有两个使用一个AppGuard和另一个AuthGuard的防护。基本上,保护装置在那里是为了保护您的某些页面免受直接访问。如果所有防护措施都返回true,则导航发生。例如,有人在您的网站上购买商品时。他可能应该是登录用户,并且您将客户重定向到登录屏幕。进一步了解canActivateauthguard

我最初的猜测是看一下AppGuard,因为它位于默认导航的canActivate属性中。尽管如此,也请签入AuthGuard。将使您清楚地知道为什么您的应用程序中有两个保护措施以及它们各自负责什么。希望有帮助。


0
投票

仔细观察并了解防护措施后,我确实看到'AppGuard'在启动时由于尚未通过身份验证而重定向到登录页面。它尝试在启动时默认为主页,但随后运行Appguard,并指示用户尚未通过身份验证,因此它将重定向到登录页面。

© www.soinside.com 2019 - 2024. All rights reserved.