gpt4 book ai didi

javascript - Angular 1.5.x 组件路由器解析 (2)

转载 作者:行者123 更新时间:2023-12-02 14:12:48 25 4
gpt4 key购买 nike

如何让组件路由在执行 Controller 并渲染 View 之前等待数据。类似于ngRouteui-routerresolve

文档中有这样的内容:

Angular Component Router

这只等待网址更改,例如:

//Old url
http://localhost/#/

// wait the promise (eg 1s) and then change the url to
http://localhost/#/heroes

但是点击链接后 View 立即改变,然后url也改变了,太奇怪了!

这不会阻止 View 渲染或 Controller 执行(显然)。

Demo of this situation:

Code and preview: plunkr.co (click in heroes)

有一个类似的问题没有答案:Angular 1.5.x Component Router Resolve

最佳答案

我找到了解决方案:

这应该在组件定义中配置:

.component('myComponent', {
templateUrl: './my-compnent.html',
controller: MyComponentCtrl,
$canActivate: function($nextInstruction, $prevInstruction) {
return Promise.resolve(<true or false>);
}
})

关于javascript - Angular 1.5.x 组件路由器解析 (2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39358651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com