【问题标题】:Remove a component from history in angular 2从角度 2 中的历史记录中删除一个组件
【发布时间】:2017-04-02 16:33:29
【问题描述】:

我如何限制组件在后按时加载。 实际上,我有三个组件 A(普通组件)、B(登录组件)和 C(OTP 验证组件)。 我在单击某个按钮时从 A 路由到组件 B,从 B 路由到 C 以验证用户。 现在在组件 C 上完成验证后,我想返回组件“A”,并希望从历史记录中删除组件“B”和“C”,以便在浏览器的后按时不会加载“B”(登录组件)又是“C”。 那么我怎么能在 angularjs 2 中做到这一点。

【问题讨论】:

  • 我想你可以使用路由守卫。 RouteGuards
  • 它们允许您连接到组件生命周期,让您能够取消导航。

标签: angular typescript angular2-routing angular-components angular-component-router


【解决方案1】:

从组件 B 和 C 导航时,传递选项 replaceUrl:true 以在浏览器历史记录中将 B 替换为 C。

例如:

//Navigating to state C 
this.router.navigate(["/C"], { replaceUrl: true });

查看documentation for replaceUrl

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-19
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 2013-03-22
    • 1970-01-01
    相关资源
    最近更新 更多