Angular JS not redirecting to a new template (ngRoute)

65 Views Asked by At

I have got my routing set as this:

function routing($routeProvider) {
$routeProvider
    .when('/', {
        templateUrl: 'templates/registration.html'
    }).when('/chatroom', {
        templateUrl: 'templates/ChatRoom.html',
        controller: 'mainController'
    });
}

messagingApp.config([
    '$routeProvider',
    '$locationProvider',
    routing
]);

When I go localhost:8080/ it successfully loads the registration.html. My registration.html is as follows:

<a href="#/chatroom">Click</a>

When I click on the a tag above it still only shows registration.html. The url after click a tag becomes http://localhost:8080/#!/#%2Fchatroom. I want it to load ChatRoom.html instead when is clicked. Any help would be appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

Add this in html <head> section:

<base href="/">

Add this in routes:

$locationProvider.html5Mode(true);

In anchoring elements remove # before url.

Probably this will solve your proble