Angular 角度路由-区分新页面请求和来自不同模块的导航
在我的Angular应用程序中,我有一个仪表板组件,它将显示在加载的第一页上。当应用程序被加载时,我想向用户展示一些让他开始的提示。当他从另一个组件导航到仪表板时,我不想显示这些提示Angular 角度路由-区分新页面请求和来自不同模块的导航,angular,routing,Angular,Routing,在我的Angular应用程序中,我有一个仪表板组件,它将显示在加载的第一页上。当应用程序被加载时,我想向用户展示一些让他开始的提示。当他从另一个组件导航到仪表板时,我不想显示这些提示 如何区分新页面请求和从不同页面导航到仪表板的用户?我们通过在代码中放置解析器来实现这一点。它将在路由到达页面之前解析或执行。此时,您可以检查用户是直接访问还是来自其他页面。根据这一点,您可以显示内容 @Injectable() export class DashResolverService implements
如何区分新页面请求和从不同页面导航到仪表板的用户?我们通过在代码中放置解析器来实现这一点。它将在路由到达页面之前解析或执行。此时,您可以检查用户是直接访问还是来自其他页面。根据这一点,您可以显示内容
@Injectable()
export class DashResolverService implements Resolve<any> {
constructor(private router: Router) { }
public resolve(route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<any> | TitleResolverData {
// this will give you weather you are coming from start or from another page
if (!this.router.routeReuseStrategy.shouldAttach(route)) {
return Observable.of(something);
// you have data
} else {
return {
title: 'Dashboard - ' + route.params.xxxx
}
};
}
}
这些是可用的方法
*/
export declare abstract class RouteReuseStrategy {
/** Determines if this route (and its subtree) should be detached to be reused later */
abstract shouldDetach(route: ActivatedRouteSnapshot): boolean;
/** Stores the detached route */
abstract store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle | null): void;
/** Determines if this route (and its subtree) should be reattached */
abstract shouldAttach(route: ActivatedRouteSnapshot): boolean;
/** Retrieves the previously stored route */
abstract retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle | null;
/** Determines if a route should be reused */
abstract shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean;
}
*/
export declare abstract class RouteReuseStrategy {
/** Determines if this route (and its subtree) should be detached to be reused later */
abstract shouldDetach(route: ActivatedRouteSnapshot): boolean;
/** Stores the detached route */
abstract store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle | null): void;
/** Determines if this route (and its subtree) should be reattached */
abstract shouldAttach(route: ActivatedRouteSnapshot): boolean;
/** Retrieves the previously stored route */
abstract retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle | null;
/** Determines if a route should be reused */
abstract shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean;
}