3

At the moment I have html5 mode turned for url's in my angular site.

But I was just wondering is there anyway I could have my default url load without the "#!/" i.e. domain/#!/, I know I will have it back when I switch to a route but would be nice to not have it in default url homepage.

Here is my current routeprovider

app.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider){
  'use strict';
  $routeProvider
    .when('/',{
      templateUrl: '/views/search.html',
      controller : 'SearchCtrl'
    })
    .when('/result',{
      templateUrl: '/views/result.html',
      controller : 'resultCtrl'
    })
    .when('/options',{
      templateUrl: '/views/options.html',
      controller : 'optionsCtrl'
    })
    .otherwise({
      redirectTo: '/'
    });
  $locationProvider.html5Mode(false);
  $locationProvider.hashPrefix('!');
}]);
1
  • I doubt there's anything you could do that wouldn't be considered a hack. The prefix is something handled internally to ngRoute. Is it really that much of a problem? Your home url will still work with or without it. Commented Dec 12, 2014 at 17:26

2 Answers 2

9
+100

Hashbang mode is a fallback for html5, so either

  • use html5
  • hack angularjs
  • put homepage out of angular application
  • rewrite/forward urls on web server

Read more on $location.

Sign up to request clarification or add additional context in comments.

Comments

0

if you are not using server side language then put this code in html head.

<base href="/">

like :

<head>
    <base href="/">
</head>

and put this in config block:

$locationProvider.html5Mode(true);

if you are using server side language then use this code:

app.get('*', function(req, res) {
    res.render('index');
});

insteed of

app.get('/', function(req, res) {
    res.render('index');
});

and and put this code in config block:

$locationProvider.html5Mode(true);

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.