$routeProvider does not route

45 Views Asked by At

I am trying to redirect the url using the $routeprovider

$routeProvider.when('/', {
            templateUrl : 'scripts/login/login.tpl.html',
            controller : 'LoginCtrl'
        });
        $routeProvider. when('/sample', {
      templateUrl: 'sample.html'
    });
        $routeProvider.otherwise({
            redirectTo : '404.html'
        });

Below is the url which loads the application

http://localhost:8080/orion-web/app/

when I try to append the word 'sample' to the url ie

http://localhost:8080/orion-web/app/sample

I get 404 error , This is not the 404.html from the $routeprovider. It's tomcats 404 resource not found page

3

There are 3 best solutions below

3
Manoj Meria On

  $routeProvider
   .when('/', {
            templateUrl : 'scripts/login/login.tpl.html',
            controller : 'LoginCtrl'
        })
    . when('/sample', {
      templateUrl: 'sample.html'
    })
    .otherwise({
            templateUrl: '404.html'
        });

Use this code

1
Martin On

Do you have a base url set for your page?

It should be <base href="/orion-web/app/"> within the header section of your index.html

0
Ujjwala Bollam On

In the second $routeprovider.when try removing /

$routeProvider. when('sample', {
  templateUrl: 'sample.html'
});