![](/img/trans.png)
[英]Error 404 when directly access to a route in EmberJS distribution app
[英]Emberjs application refresh on route other than index gives 404 error
我有一個使用Ember-App-Kit(EAK)提供的入門套件的小型 ember 應用程序。 在構建生產后,我已將 dist 目錄上傳到 AWS EC2 實例。
我現在面臨的問題:
首先我認為這是由於權限錯誤,但它只是單個 html 文件並且 js 和 css 正在正確加載。 然后認為可能是 htaccess 問題所以嘗試插入一個,但之后也沒有效果。 應用程序源代碼的條帶化版本位於Source Code
.htaccess 文件用於重定向::
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule ^(.*)$ /index.html [L]
我實際上無法弄清楚如何使用 Apache 服務器來執行此操作,因此我安裝了 nginx,它使用了我在配置文件中提供的重寫規則。
server {
root /var/www/{Your App Directory Path Here};
index index.html index.htm;
server_name {Your website URL or IP address here};
location / {
try_files $uri $uri/ /index.html?/$request_uri;
}
}
您可以在此處找到更多討論: Ember-App-Kit Git Repo 問題 486
如本文所述,使用FallbackRessource是完成此任務的最簡單方法:
FallbackResource /index.html
它可以在.htaccess
中使用,但由於 .htaccess 在每個請求上都會被解析,我建議將它放在 httpd.conf 或虛擬主機中。
無論訪問什么 URL,您都需要確保您的 Web 服務器為您的“索引”頁面提供服務。
對於 Apache,您通常會使用重寫規則,這里有一些關於為 Ember 設置此規則的討論http://discuss.emberjs.com/t/apache-rewrite-rule-for-html5-browser-history-url-bookmarkability/ 1013
您需要在構建之前在 environment.js 中設置locationType: 'hash'
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.