2

I have a problem with my angularjs routes. My simplified route config looks like:

App.config([ '$routeProvider', function( $routeProvider ) {

$routeProvider.
  when('/', {  
      redirectTo: '/home'
  }).
  when('/home', {
    templateUrl: 'home.html',
    controller: 'HomeCtrl'
  }).
  when('/404', {   
      templateUrl: '404.html'
  }).
  when('/500', {   
      templateUrl: '500.html'
  }).
  when('/:tabName', {   
      templateUrl: 'tabView.html',
      controller: 'TabContentCtrl'
  }).
  when('/:tabName/:widgetName', {    
      templateUrl: 'tabView.html',
      controller: 'TabContentCtrl'
  }).
  otherwise({                    
      redirectTo: '/404'
  });
}]);

The problem is when I put URLs http://myapp or http://myapp/ into browser, it redirects me nowhere, nothing takes place, even redirect to 404 error page. It starts working when I put hash to URL http://myapp/#, then it works as I expected. But why my default route for root URL of application http://myapp, and http://myapp/ did not work?

2 Answers 2

3

You just need to enable html5mode:

config javascript

App.config([ '$routeProvider', function($routeProvider, $locationProvider) {
  $locationProvider.html5Mode(true);
}]);

index.html

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <base href="/">
  </head>
</html>
Sign up to request clarification or add additional context in comments.

Comments

0

It depends on how have you set your virtual host and is it pointing to your root index.html? If yes, then if you type http://myapp it would definitely take you to http://myapp/#/home

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.