Angular HTML5模式,路由器将以其他方式在页面上重新加载 [英] Angular HTML5 mode, router going to otherwise state on page reload
问题描述
我正在尝试从我的网站中删除哈希标签。我是通过以下代码实现的。
I am trying to remove hash tag from my website. I have achieved it by following code.
$locationProvider.html5Mode(true);
以及在索引文件中添加的基本URL。
As well as added base URL in index file as well.
我的问题是重新加载整个页面后是否处于按状态使用。我将重定向到定义为其他状态的本国状态。
My issue is if i am on contct-us state after reloading entire page. i am redirecting to home state which is defined as otherwise state.
使用的配置--
服务器-Appache
数据库-mysql
server -Appache database - mysql
我还在.htaccess中添加了以下代码以重写规则-
I have added following code in .htaccess for rewriting rule as well -
RewriteEngine On
php_value post_max_size 120M
php_value upload_max_filesize 120M
php_value max_execution_time 90
RewriteCond %{HTTP_HOST} ^54\.201\.153\.244$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} ^adkarlo.com$ [NC]
RewriteRule ^(.*)$ https://www.adkarlo.com/$1 [R=301,L]
#RewriteBase /html/
ErrorDocument 404 /404.php
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^(.*)$ index.php [L]
预期资源ult-从状态contact-us重新加载后,我想转到任何页面。
Expected result - After reloading from state contact-us any page i want to go to same page.
推荐答案
为了支持重新加载HTML5模式路由URL,您需要实现服务器端URL重写,以将非文件请求(即,不是显式存在于现有文件的请求)定向到索引文件,通常是 index.html
。
In order to support reloading of HTML5 mode route URLs, you need to implement server-side URL rewriting to direct non-file requests (that is, requests that aren't explicitly for an existing file) to your index file, typically index.html
.
来自文档
使用此模式需要在服务器端重写URL,基本上,您必须重写所有链接到您的应用程序的入口点(例如index.html)。
Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html).
您的重写规则中不应包含任何#
目标网址。而是使用此
Your rewrite rule should not have any #
in the destination URL. Instead, use this
RewriteEngine on
# Don't rewrite files
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.php [L]
来源〜 https://github.com/angular-ui/ui-router/wiki/常见问题解答#如何配置您的服务器以使用html5mode
此外,也无需设置 RewriteBase
。
这篇关于Angular HTML5模式,路由器将以其他方式在页面上重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!