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

Asked

Viewed 1,389 times

2

By default Angularjs formats the URL as follows:

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

How do I leave it this way?

http://dominio.com.br/login

1 answer

3


It’s two very simple steps:

  • Enable HTML5 on $locationProvider
  • Configure the application’s base 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);
    });

Set base url in the application index

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

Source: Pretty Urls in Angularjs: Removing # (In English)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.