加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

html – angularjs视图仅在硬刷新时加载而不在重定向上加载

发布时间:2020-12-14 18:39:16 所属栏目:资源 来源:网络整理
导读:我正在开发我的角应用程序,并设置了这样的路线 angular.module('app',['ngRoute']) .config(function ($routeProvider,$locationProvider) { $routeProvider.when('/',{ template : "",controller : function($window) { $window.location.href = '/'; } }).
我正在开发我的角应用程序,并设置了这样的路线

    angular.module('app',['ngRoute'])
        .config(function ($routeProvider,$locationProvider) {
            $routeProvider.when('/',{
                template : "",controller : function($window) {
                $window.location.href = '/';
                }
            }).when('/test',{
                    redirectTo : '/test/dashboard'
            }).when('/test/dashboard',{
                    templateUrl : '../partials/dashboard.html',controller : 'DashboardController'
            }).when('/test/unit',{
                    templateUrl : '../partials/unit.html',controller : 'unitController'
            });
            $locationProvider.html5Mode(true);
    });

HTML是

<body ng-app="app">
    ...
    <div id="sidebar-wrapper" class="fill-height sidebar-nav">
      <ul class="tabRow nav nav-stacked">

        <li ng-class="{active: isActive('dashboard') }"><a id="dashboardLink" ng-href="#test/dashboard">Dashboard</a>
        </li>

        <li ng-class="{active: isActive('unit') }"><a id="unitLink" ng-href="#test/unit">Unit</a>
        </li>
      </ul>
    </div>
    ...
</body>

问题:

当我输入“/ test”时,此代码会将URL重定向到“/ test / dashboard”,但该页面的html不会显示.但是,当我使用该路由刷新页面时,它会在页面的内容区域中显示html.

当我在链接之间切换时,仪表板显示,只是在第一次导航时不加载.

此外,当我将重定向更改为/ test / unit时,它会正确重定向并显示unit.html.

不确定是什么导致了这种行为.

任何帮助,将不胜感激.

解决方法

我认为你需要为$locationProvider配置html5Mode时指定requireBase:false
$locationProvider.html5Mode({
  enabled: true,requireBase: false
});

这是一个工作plnkr demo

有关与部署相关的更多上下文,您应该了解this表单角度文档

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读