我想知道是否有人可以告诉我,当您将模式更改为Angular js中的html5时,需要完成哪些服务器端更改。因为当我尝试将其更改为html 5模式时,我无法进入我的内部html页面。在Angular API中,它表示suers需要做一个服务器端更改。服务器端更改Angular html5模式
- 什么是服务器端更改
- 做我们需要做任何其他的变化呢?
我想知道是否有人可以告诉我,当您将模式更改为Angular js中的html5时,需要完成哪些服务器端更改。因为当我尝试将其更改为html 5模式时,我无法进入我的内部html页面。在Angular API中,它表示suers需要做一个服务器端更改。服务器端更改Angular html5模式
你应该区分两种类型的呼叫:从浏览器
如何区分这两种类型的调用,以及如何重新映射前者,很大程度上取决于您的设置。
如果使用nginx的,例如,检查$ HTTP_ACCEPT的组合是application/json
(见http://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Requests和http://wiki.nginx.org/HttpCoreModule#.24http_HEADER)和重写(http://wiki.nginx.org/HttpRewriteModule#rewrite),你可以达到你想要的东西。
你需要设置你的服务器重写一切index.html的每个:https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode ...
<VirtualHost *:80>
ServerName my-app
DocumentRoot /path/to/app
<Directory /path/to/app>
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule^- [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule^index.html [L]
</Directory>
</VirtualHost>
我的应用程序已经PARAMS传递给控制器(通过UI路由器),所以html5mode我会转到前 www.blah.com/angapp/#/myUIrouterController?param_x=1 & param_y = 2 猜测浏览器知道/#/文件夹路径部分应该为index.html提供服务。
现在,#将与html5mode一起消失,服务器默认情况下不知道为该文件夹提供index.html,因为url只是: www.blah.com/angapp/myUIrouterController?param_x= 1 & param_y = 2 myUIRouterController不是一个真正的文件,所以服务器只会提供一个404,因此为什么我认为需要重写,所以它知道要发送一切到index.html(所以上面结合<基地>标签应该工作...注意:requireBase是可选的,但听说它可以帮助IE9等旧版浏览器)。
我还没有做过这件事,但我相信你需要重写你的URL,以便它们指向你的index.html(即当你请求'/ index.html'时,服务器会输出'/ index.html' /接触/伦敦office')。如果您使用的是Apache,请查看'mod_rewrite'。 –