javascript - ui-router (0.3.2) 不会为历史记录上的正则表达式状态参数触发`$stateChangeStart`
问题描述
请参阅此堆栈闪电战。请注意,我正在使用Angularjs@1.5.7
and ui-router@0.3.2
。
它定义了以下 ui-router 状态:
$stateProvider
.state('counter1', {
url: '/counter1/{id:(NEW-ID-\d+|)}?detail',
templateUrl: 'view/counter.html',
controller: ['$scope', '$state', '$interval', counterController]
})
.state('counter2', {
url: '/counter2/:id?detail',
templateUrl: 'view/counter.html',
controller: ['$scope', '$state', '$interval', counterController]
})
两种状态是相同的,只是counter1
将参数定义id
为正则表达式,而counter2
以简单的方式定义它。
问题是,通过这个counterController
设置
$scope.$on('$stateChangeStart', () => console.log('$stateChangeStart'))
只会为counter2
路由触发,不会counter1
在用户使用浏览器的后退或前进功能时触发。奇怪的是,它确实会触发例如state.go()
或单击ui-sref
链接。
如果counter1
路由中的正则表达式更改为{id:.*}
它确实可以按预期工作,但对于我的用例,我需要将其定义为{id:NEW-ID-\d+|}
. 这是一个已知的错误吗?是否有任何其他解决方法可以确保$stateChangeStart
实际触发正确?我还没有找到任何东西,我会很感激你的想法。
解决方案
推荐阅读
- java - DynamoDB 嵌套映射到 Java 对象
- nuxt.js - Tailwind+ Nuxt:@apply 不适用于所有课程
- python - 是否可以将一个线程的结果通过管道传输到另一个线程?
- terraform - 错误:不允许对具有 VCS 连接的工作区应用
- python-3.x - 如何使用 BeautifulSoup 抓取标签之间的嵌套文本?
- ios - RAD Studio 10.4.1 尝试运行“无法创建进程:/Applications/PAServer-21.0.app/Contents/MacOS/dbkosx_27_0”时出现我的第一个 iOS 应用程序错误
- machine-learning - 就大 O 表示法而言,O(N*P) 是什么类别,P 表示特征大小,如在朴素贝叶斯或 kNN 中所见?
- reactjs - 使用特快专递和反应
- c# - ASP.NET Core Web API Docker Linux 拒绝连接
- c++ - 你应该如何使用带有 URDF 的控制器