带有路由(状态)的延迟加载angularjs子模块的问题

时间:2019-05-28 07:36:37

标签: angularjs angular-ui-router angularjs-module

我正在使用angularjs + ui-router应用程序,这是我的另一个angularjs应用程序(基本上是页眉+页脚+ sidenav)的shell应用程序。 我正在开发的每个应用程序都被编译并存储为npm库,该库最终用作我的shell应用程序的package.json中的依赖项。 加载shell应用程序时,将根据shell应用程序中定义的状态来决定应将其他应用程序中的哪个呈现为ui视图内容。

这是shell应用程序状态定义:

    $stateProvider
    .state('content', {
        url: '/:appName', ...

在子应用程序中定义了一些其他状态,这些状态使用“内容”状态作为父状态,例如:

$stateProvider.state('child', {
url: '/child1',
parent: 'content',
component: 'childComponent'});

仅在已加载所有内容之后,路由才能按预期工作。 问题在于,在每次浏览器刷新时,shell应用程序都会首先加载,例如在该特定点上,将以下路径加载: http://localhost:8000/#/childapp1/chid1 无效,因为尚未加载子路由(状态)。 我随附的唯一解决方案是将url存储在全局变量中,然后将其用作“返回url”模式,该方法有效。 我想知道我的问题是否有更好的解决方案。

感谢您的帮助,

N

0 个答案:

没有答案
相关问题