AngularJS ui-router 应用程序在 URL 中有/#!/ [英] AngularJS ui-router application has /#!/ in the URL

查看:25
本文介绍了AngularJS ui-router 应用程序在 URL 中有/#!/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ui.router 的应用程序正常工作,但另一个应用程序的 url 在 "#" 之后有一个 "!" "!"/p>

例如:http://localhost:8090/dev/#!/home

为什么会这样?

正常的应该是:http://localhost:8090/dev/#/home

解决方案

我想这是因为 hashprefix 没有设置.

$locationProvider.hashPrefix('!');

我猜您可以将其设置为空字符串,这就是您看不到 ! 的原因.

或者,您可以启用 html5mode 这将完全摆脱hashbang`.一些较旧的浏览器不支持它,但通常不是问题,除非您需要支持 IE9 或其他东西.

你可以阅读它,例如此处这里.

长话短说,如果您正确配置 html5mode,那么您将不会拥有 hashbang 在不支持它的旧浏览器中路由所需的 hashbang.>

I have an application with ui.router working normally, but another application the url has an "!" after "#"

Ex: http://localhost:8090/dev/#!/home

Why it happens?

The normal should be: http://localhost:8090/dev/#/home

解决方案

I suppose this happens because hashprefix is not set.

$locationProvider
  .hashPrefix('!');

I guess you can set it to empty string and that is why you don't see !.

Alternatively you can enable html5modethat will get rid ofhashbang` completely. Some older browsers don't support it, but generally not an issue, unless you need to support IE9 or something.

You can read about it e.g. here or here.

Long story short if you configure html5mode properly, then you won't have the hashbang that is required for routing in older browsers that do not support it.

这篇关于AngularJS ui-router 应用程序在 URL 中有/#!/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆