0

So I'm trying to use angular routing in my application. The problem is that the route "/" does not get initialized automatically. So I first go to "/" and the main content of the page is empty (the template is not loaded at all), I click the link to /settings and settings are loaded, then I click a link to "/" and this time the template is initialized correctly. So how do I make the thing initialized at the beginning?

Here's my routing configuration:

 app.config(function($routeProvider, $locationProvider) {
          $routeProvider
           .when('/', {
            templateUrl: '/profile.html',
            controller: 'ProfileController',
          }).when('/profile', {
            templateUrl: '/profile.html',
            controller: 'ProfileController',
          }).when('/settings', {
            templateUrl: '/settings.html',
            controller: 'SettingsController'
          });

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

I tried calling $location.url("/profile") from a controller and it did help, but the url has to be changed and I would rather keep the "/"

Kamil Janowski
  • 1,872
  • 2
  • 21
  • 43

1 Answers1

1

use otherwise({ redirectTo: "/" })

Update : here how it should be

 $routeProvider
           .when('/', {
            templateUrl: '/profile.html',
            controller: 'ProfileController',
          }).when('/profile', {
            templateUrl: '/profile.html',
            controller: 'ProfileController',
          }).when('/settings', {
            templateUrl: '/settings.html',
            controller: 'SettingsController'
          }).otherwise({ redirectTo: '/' });
maddygoround
  • 2,145
  • 2
  • 20
  • 32