什么#!在ui.router中意味着什么?

时间:2021-10-29 19:41:09

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

我正在使用Angular ui.router来浏览我的应用程序。通常,网址应如下所示:

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.

我也认识到如果我从这个站点调用一个与我的起始页不同的URL,我总是被重定向,因为URL似乎无效。

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.

每当我尝试调用localhost:8001 /#/ registration / activate / xyz时,我都会被重定向到起始页面。

2 个解决方案

#1


2  

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:

好的,谢谢你的解释。我解决了我的问题,我无法通过将链接添加到我的配置来调用链接中的URL:

$locationProvider.hashPrefix('');

#2


0  

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

如果浏览器是HTML5浏览器,angularJS会将其重定向到#!

Otherwise it will be only #.

否则它只会#。

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

请在$ location上阅读此文档,了解更多有关这种情况的原因。

  • Opening a regular URL in a legacy browser -> redirects to a hashbang URL
  • 在旧版浏览器中打开常规URL - >重定向到hashbang URL

  • Opening hashbang URL in a modern browser -> rewrites to a regular URL
  • 在现代浏览器中打开hashbang URL - >重写为常规URL

#1


2  

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:

好的,谢谢你的解释。我解决了我的问题,我无法通过将链接添加到我的配置来调用链接中的URL:

$locationProvider.hashPrefix('');

#2


0  

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

如果浏览器是HTML5浏览器,angularJS会将其重定向到#!

Otherwise it will be only #.

否则它只会#。

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

请在$ location上阅读此文档,了解更多有关这种情况的原因。

  • Opening a regular URL in a legacy browser -> redirects to a hashbang URL
  • 在旧版浏览器中打开常规URL - >重定向到hashbang URL

  • Opening hashbang URL in a modern browser -> rewrites to a regular URL
  • 在现代浏览器中打开hashbang URL - >重写为常规URL