【问题标题】:issues after remove of # from URL从 URL 中删除 # 后的问题
【发布时间】:2017-05-11 17:23:33
【问题描述】:

我的网址是 https://localhost/admin#/dashboard 所以我必须从 URL 中删除 #。 我遇到了从 angularJS 中的 URL 隐藏 # 的问题,所以我修改了我的代码来解决这个问题,正如在不同论坛上提到的那样。
我已经添加了

$locationProvider.html5Mode({ 启用:真, 要求基础:假 });

在我的索引中,我添加了

<base href="/admin">

这是我的 .htaccess 文件

Options +FollowSymLinks
Options +Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|satellizer|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

它工作正常,但有 2 个问题 它从 URL 中隐藏了“管理员”,并且我曾经在任何地方使用 jquery 作为 window.location.href 它向我显示不同的 URL,然后突然它重定向到没有 # 和管理员的新 URL

【问题讨论】:

  • 你确实设置了requireBase: false。但是,使用了&lt;base href="/admin"&gt;。为什么?
  • 因为它只有在我提到的设置时才能正常工作,您有更好的建议请与我分享。
  • 现在我对 requireBase 使用默认值,但它仍然显示错误。
  • 你到底面临什么错误?
  • 我当前的 URL 像这样 localhost/admin#/pet_owners 我想从 URL 中删除 # 并且我按照所有步骤从 Angular 文档中的 url 中删除 #...按照说明我的 URL 是这样的 localhost/pet_owners但我在 URL 中也需要管理员

标签: jquery angularjs url redirect


【解决方案1】:

要从 url 中删除 #,请生成 html5Mode(true)

在 .config 中这样做:

$locationProvider.html5Mode(true);

在head标签placebase标签中:

&lt;base href="/"&gt;

从你的锚定元素中删除#

别忘了注入$locationProvider

【讨论】:

猜你喜欢
  • 2017-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多