Search code examples
javascriptangularjsroute-provider

Unwanted hash '#' in url, using $routeProvider in angularjs


When I'm starting my application the following url is opened: http://localhost:8080/#/. What I'm trying to do is to open this url: http://localhost:8080/ when the application is loaded, but I'm not able to achieve this.

I'm using AngularJS and $routeProvider to load content based on url. I'm quite not sure how it works and documentation is not clear to me. This is the code:

'use strict';

angular.module('login', ['login.filters', 'login.services', 'login.directives', 'login.controllers']).
    config(['$routeProvider', function ($routeProvider) {
        $routeProvider.when('/', {templateUrl: 'partials/partial1.html', controller: 'MyCtrl1'});
        $routeProvider.otherwise({redirectTo: '/'});
    }]);

Can you help me spot unwanted '#' ?


Solution

  • Take a look here: https://scotch.io/tutorials/pretty-urls-in-angularjs-removing-the-hashtag

    This describes how to achieve what you want, as well as educating you on what the # is for and how Angular utilizes it