Sergey Panfilov Sergey Panfilov - 2 months ago 17
AngularJS Question

Angular.JS: cannot set default route when no hash

The problem is:
I cannot reach home page when url is but can when it's!

I was define default web app route:

$routeProvider.when('', {templateUrl: pathToIncs + 'home.html', controller: 'homeController'});
$routeProvider.when('/', {templateUrl: pathToIncs + 'home.html', controller: 'homeController'});

Added otherwise option:

$routeProvider.otherwise({redirectTo: '/404'});

And turn of html5 mode


As i said befor - it works when I'm came by ulr like! but not when In this case .otherwise option will be called.

In any other case routing works well. In the my app I got an urls like a!/login,!/signup

P.S. Server side works on php5+nginx
P.P.S. I'm use Angular 1.2.0 with ngRoute module


Try setting the < base > tag.

  <base href="/">

Have a route defined for home

.when('/home', {
        templateUrl: pathToIncs + 'home.html', 
        controller: 'homeController'

using redirectTo on the "/"

.when('/', {
    redirectTo: '/home'

along with the .otherwise

    redirectTo: '/home'