We tried from CMS - we changed the starting-page of site to login page, made homepage as not-default and this brought the login page. However, it’s not refreshing or redirecting to HomePage after successful login.
Is your homepage accessible only for authenticated users? If yes you can make use of protected routes (see ProtectedRoutesService) - setting homepage as default will redirect to login anyways and after authenticating user will be redirected back to the homepage.
ProtectedRoutes的意思是,此类Route是否应该activate,取决于AuthGuard.
如果是非ProtectedRoutes,则返回true.
@Injectable({ providedIn: 'root' })
export class ProtectedRoutesGuard implements CanActivate {
constructor(
protected service: ProtectedRoutesService,
protected authGuard: AuthGuard
) {}
/**
* When the anticipated url is protected, it switches to the AuthGuard. Otherwise emits true.
*/
canActivate(route: ActivatedRouteSnapshot): Observable<boolean | UrlTree> {
let urlSegments: string[] = route.url.map((seg) => seg.path);
// For the root path `/` ActivatedRoute contains an empty array of segments:
urlSegments = urlSegments.length ? urlSegments : [''];
if (this.service.isUrlProtected(urlSegments)) {
return this.authGuard.canActivate();
}
return of(true);
}
}