ハッシュ(#)を削除する場合は、すべてのパスに対してindex.html
を提供するためにサーバで書き換え機能を使用する必要があります。そうでない場合は、常に404
エラーが発生します。 404
をindex.html
にリダイレクトできるということです。
アパッチ:ここにショーとして.htaccess
ファイルに書き換えルールを追加します。
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule^- [L]
# If the requested resource doesn't exist, use index.html
RewriteRule^/index.html
nginxの:使用try_files
、フロントコントローラパターンのWebアプリで説明したように、index.html
を提供するように変更:
try_files $uri $uri/ /index.html;
IIS:書き換えルールを01に追加するここに示したものと同様、:tomcatので
<system .webserver="">
<rewrite>
<rules>
<rule name="Angular Routes" stopprocessing="true">
<match url=".*">
<conditions logicalgrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchtype="IsFile" negate="true">
<add input="{REQUEST_FILENAME}" matchtype="IsDirectory" negate="true">
</add></add></conditions>
<action type="Rewrite" url="/">
</action></match></rule>
</rules>
</rewrite>
</system>
は、web.xmlにそれを追加することができます。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<error-page>
<error-code>404</error-code>
<location>/</location>
</error-page>
</web-app>
は後に、index.html
にHTML5の歴史APIをウェブ経路をリダイレクトAngular JSではWebルートを制御するために使用されます。私たちの主な仕事は、サーバーでindex.html
と呼ばれるだけです。
あなたはnginxソリューションを手伝ってもよろしいですか? –
私は最後にやってからしばらくしていましたが、このようないくつかの要点があります:https://gist.github.com/zdwolfe/6721115 あなたが何を見せているかに加えて、画像/ javascriptファイルを提供する静的/静的。 –