Angularjs view load only on hard upgrade, not redirect

I am working on my angular app and setting up routes this way

     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> 

Problem:

This code redirects the URL to "/ test / dashboard" when you enter "/ test", but the html for this page is not displayed. However, when I refresh the page using this route, it displays html in the content area of ​​the page.

When I switch between links, the control panel appears, it just does not load the first time I enter it.

Also, when I change the redirection to / test / unit, it redirects correctly and displays unit.html.

Not sure what causes this behavior.

Any help would be appreciated.

+6
source share
1 answer

I think you need to specify requireBase: false when setting up html5Mode for your $locationProvider

 $locationProvider.html5Mode({ enabled: true, requireBase: false }); 

Here is a working plnkr demo

For more context regarding your deployment, you should know this form of angular docs

0
source

Source: https://habr.com/ru/post/987467/


All Articles