0

I use oclazyload to inject modules in my app, and ui-router to create states, everything work fine i can move between state home or users but when we change state to users.list and press F5 (refresh) state return to the otherwise state (/application/partials/index.html), what should i do to stay in users.list state after refreshing the page?

index.html

<div ng-app="app">
    <a ui-sref="/">home</a>
    <a ui-sref="users.list">users</a>

    <div ui-view></div>
    <script src="Scripts/angular.js"></script>
    <script src="Scripts/angular-ui-router.min.js"></script>
    <script src="Scripts/ocLazyLoad.js"></script>

    <script src="app.js"></script>
</div>

Main app

var app = angular.module("app", ["ui.router", "oc.lazyLoad"]);

app.config(function ($ocLazyLoadProvider, $stateProvider) {
    $ocLazyLoadProvider.config({
      modules: [{
        name: 'users',
        files: ['/application/modules/users/app.js']
      }]
    }); 

    $stateProvider.state('/', {
        url: '/',
        templateUrl: '/application/partials/index.html'
    });

    $urlRouterProvider.otherwise('/');
})

app.run(function ($ocLazyLoad) {
    $ocLazyLoad.load("users");
});

application/modules/users/app.js

var app = angular.module("users", []);

app.config(['$stateProvider', function ($stateProvider) {
    $stateProvider.state('users', {
        abstract: true,
        url: '/users',
        template: '<div ui-view="users"></div>'
    });

    $stateProvider.state('users.list', {
        url: '/list',
        module: "users",
        views: {
            "users": {
                parent: "users",
                templateUrl: '/application/modules/users/partials/index.html'
            }
        }
    });
}]);
Maher
  • 2,517
  • 1
  • 19
  • 32
  • Did you try defining `url: 'users'` in the abstract state, and define `url: 'users/list'` in `users.list` state? And before pressing F5, what is the exact url in the browser? – lzagkaretos Jan 13 '18 at 19:04
  • Hi, no need to define them, because we used nested states and adding `users` to url without `/` not work!; before refresh we have `localhost:8080/#!/users/list` after `localhost:8080/#!/` – Maher Jan 13 '18 at 19:43

0 Answers0