Angular JS default url without hash

At the moment I have html5 mode changed for url in my angular site.

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

Here is my current router

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('!');
}]);

      

+3


source to share


2 answers


Hashbang mode is fallback for html5, so either

  • use html5
  • hack angularjs
  • post home page from angular app
  • rewrite / forward urls on webserver


More on $ location .

+9


source


if you are not using a server-side language then put this code in the html header.

<base href="/">

      

like:

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

      

and put this in a config block:

$locationProvider.html5Mode(true);

      



if you are using server side language use this code:

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

      

insteed

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

      

and put this code in the config block:

$locationProvider.html5Mode(true);

      



0


source







All Articles