【问题标题】:Get state given url with ui-router AngularJS 1.x使用 ui-router AngularJS 1.x 获取状态给定的 url
【发布时间】:2015-11-04 11:56:57
【问题描述】:

如何将当前 URL 转换为相应的状态?结果状态将用于使用 $state.go 进行状态转换。

示例: http://localhost/auth/enterprise/

注册路线:

{
"stateName": "auth.context",
"url": ":context"
}

结果:auth/enterprise/ => auth.context

示例: http://localhost/auth/enterprise/esdrubal

注册路线:

{
"stateName": "auth.context",
"url": ":context/:username"
}

结果:auth/enterprise/esdrubal => auth.context

【问题讨论】:

  • 你想达到什么目的?用于身份验证的某种回调 URL?例如对于 OAuth ?在这种情况下,没有客户端 JS 能够做到这一点
  • 我要做的是将当前 URL 转换为注册状态,并在 $state.go 上使用该状态进行转换。

标签: javascript angularjs angular-ui-router


【解决方案1】:

解决方案

您可以使用 $stateProvider 上的 .decorator 挂钩公开内部状态实现。您可以装饰状态生成器的任何属性;我随意选择了“父母”。

https://stackoverflow.com/a/30926025/5485700

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-21
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    • 2014-09-22
    • 2016-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多