我已经在 Apache Tomcat 版本 9 中部署了我的 ember 应用程序。

索引页工作正常localhost:8080/myemberapp/ 但是当我尝试访问 localhost:8080/myemberapp/login它返回 404 error .

我还阅读了 URL 重写并将以下代码片段添加到 .htaccess文件

#html5 pushstate (history) support: 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteRule ^index\.html$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule (.*) index.html [L] 
</IfModule> 

并将以下内容添加到tomcat conf/context.xml文件

<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />

但在 Apache Tomcat 中部署后,我仍然无法访问任何其他 ember 路由。

谁能解决这个问题,让 ember 应用程序中的每个路由都可以映射到自定义 URL。

请您参考如下方法:

当我在 Github GH 页面中部署我的 ember 应用程序时,我遇到了这个问题。 这里的问题是,当您访问 localhost:8080/myemberapp/login 路由时,您的服务器会在登录路由或 login.html 文件中查找 index.html。

因此,为了克服这个问题,您需要提及 myemberapp 之后的所有路由都是 虚拟路由,为了提及您需要在您的 Ember 应用程序的 config/environment.js 文件中将 locationType 属性的值更改为 hash Ex .

locationType 属性的值为 hash 时,# 符号将被插入到您的应用程序的 url 中,因此您的应用程序的 url 将更改为 localhost:8080/myemberapp#/login Refernce

Example Ember app's repo您可以查看该应用 here


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!