【问题标题】:How to make AngularJS route works with index.html/#/myPage like index.html#/myPage如何使 AngularJS 路由与 index.html/#/myPage 一起使用,如 index.html#/myPage
【发布时间】:2015-04-09 01:30:45
【问题描述】:

我当前的 iFrame 页面加载了 index.html#/myPage,它在 Chrome 或 Safari 下运行良好,但不适用于 IE 11

我在 SO 上找到了this solution: 在 # (index.html/#/myPage) 之前添加 / 即可解决您的问题

它看起来很简单,但在我的例子中,它会产生一个 404 Page not found

好像我的路由提供者不支持#前面的/,为什么?

路由代码:

appSkeleton.config(
    function ($routeProvider) {
    $routeProvider.
            when('/', {
                template: '<skeleton-manage></skeleton-manage>'
            })
            .when('/skeletonManage', {
                template: '<skeleton-display-and-manage></skeleton-display-and-manage>'
            })
           .when('/employeeManage/:employeeId/:displayMode/:idItemClick?', {
                template: '<employee-display-and-manage></employee-display-and-manage>'
            })          
            .otherwise({
                redirectTo:'/'
            });

    }
);

应用程序在 Node.JS 服务器上运行

【问题讨论】:

  • 因为您使用的任何网络服务器都将/index.html/ 视为不是/index.html 相同的资源。这是正常。您可以使用某种别名或 URL 重写在 Web 服务器级别更改此行为。取决于为该资源提供服务的内容。
  • 你能告诉我们你的路由代码吗?以及哪个版本的 IE?

标签: javascript html angularjs iframe angular-ui-router


【解决方案1】:

它不适用于 app/index.html#/ 但它适用于 app/#/,您无需在 URL 上指定 index.html 或者您可以通过代码直接重定向到没有 index.html 的 URL

var url =  window.location.href;
      if(url.indexOf("index.html") > 0){
          window.location.replace(url.replace("index.html",""));
}

【讨论】:

    猜你喜欢
    • 2021-01-31
    • 2012-12-05
    • 1970-01-01
    • 1970-01-01
    • 2013-11-05
    • 1970-01-01
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多