7

I am using the Angular ui.router to navigate through my application. Usually, the url should look like this:

http://localhost:8001/#/start

But in my case, it looks like this:

http://localhost:8001/#!/start

What does it mean?

I also recognized that if I am calling an URL from this site which is different from my start page, I always get redirected as the URL seems to be invalid.

mainApp.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
'use strict';
$urlRouterProvider.otherwise('start');
$stateProvider
    .state('start', {
        url: '/start',
        templateUrl: 'views/start.html'
    })
    .state('registration-activate', {
        url: '/registration/activate/{activationKey}',
        templateUrl: 'views/registration-activation.html'
    })
    ;
    }]);

Whenever I try to call localhost:8001/#/registration/activate/xyz I get redirected to the start page.

TheWieand
  • 253
  • 3
  • 18
  • 2
    http://stackoverflow.com/questions/40478676/i-am-using-angular-and-my-url-always-has-a-exclamation-mark/40478862 – Taki Dec 25 '16 at 01:06
  • I checked my configuration, but I didn't set the hashPrefix. Is it a matter that I use gulp to simulate a webserver? – TheWieand Dec 25 '16 at 01:16

2 Answers2

3

Okay guys, thanks for your explanations. I resolved my problem that I can't call a URL from a link simply by adding this to my configuration:

$locationProvider.hashPrefix('');
TheWieand
  • 253
  • 3
  • 18
0

If the browser is HTML5 browser angularJS will redirect it to #!

Otherwise it will be only #.

Read this documentation here on $location to find out more on why this happens.

  • Opening a regular URL in a legacy browser -> redirects to a hashbang URL
  • Opening hashbang URL in a modern browser -> rewrites to a regular URL
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108