【问题标题】:UI-Router nested route breaking on page refreshUI-Router 嵌套路由在页面刷新时中断
【发布时间】:2017-04-27 01:25:40
【问题描述】:

我希望能够在加载选项卡时刷新我的 Angular 应用程序上的页面,以加载我实现了以下内容的选项卡:

  .state('MyTemplate.Tabs.Tab',
        {
            url: '/tab',
            views: {
                'container@': {
                    templateUrl: 'App/Views/Tabs.html'
                },
                'tabs-views@': {
                    templateUrl: 'App/Views/tab.html'
                }
            }
        })

当我单击我的标签链接并加载带有控件的视图时,这非常有用,但是当我刷新页面时,它会重新加载,它会尝试加载站点的根目录并崩溃。

我试图欺骗它但没有成功:

  .state('MyTemplate.Tabs.Tab2',
        {
            url: 'tabs/tab',
            views: {
                'container@': {
                    templateUrl: 'App/Views/Tabs.html'
                },
                'tabs-views@': {
                    templateUrl: 'App/Views/tab.html'
                }
            }
        })

任何帮助将不胜感激。

更新状态:

.state('MyTemplate',
{
    url: '',
    abstract: true,
    views: {
        'header': {
            templateUrl: 'App/SharedViews/header.html'
        },
        'footer': {
            templateUrl: 'App/SharedViews/footer.html'
        }
    }
})

.state('MyTemplate.Tabs',
        {
            url: '/tabs',
            views: {
                'container@': {
                    templateUrl: 'App/Views/Tabs.html'
                }
            }
        })

【问题讨论】:

  • 能否提供MyTemplate.TabsMyTemplate状态
  • 当然,更新了答案。
  • 嗯,你在 URL 中使用默认的 #/html5mode 吗?
  • 我正在使用 html5mode > $locationProvider.html5Mode(true);
  • 因此,它绝对会改变上下文,HTML5 History APIserver-side 配置存在问题。您能否使用有关服务器如何管理 Angular 应用程序的信息更新您的问题。

标签: angularjs angular-ui-router


【解决方案1】:

所以我相信您可以尝试使用以下方式配置 IIS 10:

<rewrite>  
  <rules>  
    <rule name="Imported Rule 1" stopProcessing="true">  
      <match url="^(.*)$" ignoreCase="false" />  
      <action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />  
    </rule>  
  </rules>  
</rewrite>  

在您的 web.config 中(在配置/system.webServer...等内部):

也看这里Symlink created with mklink not working with IIS7.5 -- Windows 7

重写 HTML5 历史规则(apache 示例)

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(js|css|img|svc)($|/) - [L]
RewriteRule ^(.*)$ index.html [L]

【讨论】:

  • 我很快就会试一试,我已经为刷新设置了重写规则(不适用于嵌套选项卡),但正在使用锚点。跨度>