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

时间:2016-07-11 20:34:46

标签: javascript angularjs route-provider

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 '#' ?

2 个答案:

答案 0 :(得分:0)

Angular will load pages dynamically and stores/reads the current page from in the url after the # symbol.

You could try enabled html5 mode for location How to remove the hash # from the angularjs ng-route

答案 1 :(得分:-1)

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