角UI路由器和ocLazyLoad [英] Angular ui-router and ocLazyLoad
问题描述
情景:
我有一些角模块,如:
angular.module('应用',['app.core','app.views']); //不懒负载
在 app.views
每个模块使用RouterUtil注册自己的路线,如:
Each module under app.views
uses a RouterUtil to register their own route, like:
$ stateProvider.state(国家名称,{/ *这里的一些CONFIGS * /});
此RouterUtil也有访问所有注册的状态(用于创建动态菜单)的方法。
This RouterUtil also have a method to access all registered states (used to create a dynamic menu).
和我使用的 ocLazyLoad ,只是加载外部模块。
当页面正在加载,ocLazyLoad将执行与一些角模块等JS请求,然后将此模块添加到实际的环境的
And I'm using the ocLazyLoad, just to load an external module. When the page is loading, ocLazyLoad will perform a request to other js with some angular modules, and then add this module to the actual enviroment.
当我去这个外部模块的网页,并尝试刷新页面发生问题:
The problem happens when I go to a page of this external module, and try refresh the page:
这是怎么回事:
- 角启动,并注册一些$州
- ocLazyLoad开始为外部模块 的请求
- UI的路线尝试解析实际的URL,并且意识到有这个URL没有状态,将用户重定向到默认值(否则)页
- ocLazyLoad共完成请求和所有的新模块添加到角的环境的。在这个时刻,我们有请求的URL的状态(同前刷新)
- Angular starts and register some $states
- ocLazyLoad starts a request for the external module
- ui-routes try parse the actual URL, and realizes that there is no state for this URL and redirect the user to default (otherwise) page
- ocLazyLoad finishs the request and add all new modules to angular enviroment. At this moment we have a state with the requested URL (same of before refresh)
我可以做UI路由器等待ocLazyLoad要求检查之前,如果该注册网址?
Can I do ui-router wait for the ocLazyLoad request before check if this a registered URL?
推荐答案
要使用 deferIntercept()
,以便从观看网址延迟UI的路由器。
you want to use deferIntercept()
, in order to delay ui-router from watching the URL.
app.config(function($urlRouterProvider) {
urlRouterProvider.deferIntercept();
});
... ocLazyLoad stuff
app.run(function($urlRouter) {
ocLazyLoadPromise.then(function() { urlRouter.listen(); });
});
的http://angular-ui.github.io/ui-router/site/#/api/ui.router.router.$urlRouterProvider
http://angular-ui.github.io/ui-router/site/#/api/ui.router.router.$urlRouterProvider
这篇关于角UI路由器和ocLazyLoad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!