How to remove the hashtag (#) from the URL?

2

By default AngularJs formats the URL as follows:

http://dominio.com.br/#/login

How do I leave it as follows?

http://dominio.com.br/login

    
asked by anonymous 07.06.2016 / 17:05

1 answer

3

It's two simple steps:

  • Enable HTML5 in $locationProvider
  • Configure the base application path

Enable HTML5

angular.module('app', [])
  .config(function($routeProvider, $locationProvider) {
    $routeProvider
      .when('/', {
        templateUrl : 'home.html',
        controller : homeController
      })
      .when('/sobre', {
        templateUrl : 'sobre.html',
        controller : sobreController
      });

      // habilitar o uso da API HTML5 History
      $locationProvider.html5Mode(true);
    });

Define url base in application index

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

Source: Beautiful URLs in AngularJS: Removing # >

    
07.06.2016 / 17:05