[英]when component complete render then change route in angular 2
I have a WhatsNew
Component and this my route config: 我有一个
WhatsNew
组件,这是我的路由配置:
@RouteConfig([
{ path: '/whatsnew', name: 'WhatsNew', component: WhatsNew },
])
I'm in the other route and component. 我在另一条路线和组件中。 My problem is that I want
whatsnew
to be completely rendered, then route change and navigate to WhatsNew
. 我的问题是我希望完全渲染
whatsnew
,然后路由更改并导航到WhatsNew
。 I don't want user see the rendering page, how to do it in angular 2? 我不希望用户看到渲染页面,如何在角度2中显示它?
You can implement the CanActivate
lifecycle callback. 您可以实现
CanActivate
生命周期回调。 This way you can either return a promise that completes to true when the call to the server returns that going to that route is fine or redirect to another route. 这样,您可以返回对服务器的调用返回到该路由的指示信息,当该请求可以完成时返回一个true,也可以重定向到另一个路由。
One problem is that CanActivate
is a decorator and DI doesn't support decorators but you need to get a reference to your service to make the server call. 一个问题是
CanActivate
是装饰器,DI不支持装饰器,但是您需要获取对服务的引用才能进行服务器调用。
This comment contains a link to a Plunker that demonstrates how DI can be used with CanActivate
该评论包含指向Plunker的链接,该链接演示了如何将DI与
CanActivate
一起使用。
There are a few issues that lifecycle callbacks don't wait for the promise to resolve before they continue the navigation. 存在一些问题,生命周期回调在继续导航之前不会等待承诺解决。 I don't remember if this applies to
CanActivate
. 我不记得这是否适用于
CanActivate
。 There is again a new router on its way and it is unlikely that issues will be fixed with the old routers. 再有就是在它的途中一个新的路由器,这是不可能的问题将被固定与旧的路由器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.