URL 重写 - Ember 到 URL 在 Apache Tomcat 上的路由?
URL rewriting - Ember Routes to URL On Apache Tomcat?
我已经在 Apache Tomcat 版本 9 中部署了我的 ember 应用程序。
索引页工作正常localhost:8080/myemberapp/
但是当我尝试访问 localhost:8080/myemberapp/login
它 returns 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 路由 Tomcat。
任何人都可以解决这个问题,以便 ember 应用程序中的每个路由都可以映射到自定义 URL。
我在 Github GH 页面中部署 ember 应用程序时遇到了这个问题。
这里的问题是当您访问 localhost:8080/myemberapp/login
路由时,您的服务器会在登录路由或 login.html 文件中查找 index.html。
因此,为了克服这个问题,您需要提及 myemberapp
之后的所有路线都是 virtual routes
,为了提及您需要更改 locationType
属性 在 Ember 应用程序 config/environment.js
文件中 hash
的值 Ex。
当 locationType
属性 的值为 hash
时,#
符号将被插入到您应用的 url,因此您应用的 url 将更改为 localhost:8080/myemberapp#/login
Refernce
Example Ember app's repo and you can view that app here
我已经在 Apache Tomcat 版本 9 中部署了我的 ember 应用程序。
索引页工作正常localhost:8080/myemberapp/
但是当我尝试访问 localhost:8080/myemberapp/login
它 returns 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 路由 Tomcat。
任何人都可以解决这个问题,以便 ember 应用程序中的每个路由都可以映射到自定义 URL。
我在 Github GH 页面中部署 ember 应用程序时遇到了这个问题。
这里的问题是当您访问 localhost:8080/myemberapp/login
路由时,您的服务器会在登录路由或 login.html 文件中查找 index.html。
因此,为了克服这个问题,您需要提及 myemberapp
之后的所有路线都是 virtual routes
,为了提及您需要更改 locationType
属性 在 Ember 应用程序 config/environment.js
文件中 hash
的值 Ex。
当 locationType
属性 的值为 hash
时,#
符号将被插入到您应用的 url,因此您应用的 url 将更改为 localhost:8080/myemberapp#/login
Refernce
Example Ember app's repo and you can view that app here