【发布时间】:2017-08-09 10:58:56
【问题描述】:
我正在尝试通过 springboot Web 应用程序提供 Angular2 应用程序。我找到了很多非常简单的示例:
https://github.com/zouabimourad/angular2-spring/tree/master/front
https://github.com/ehirsch/spring-angular2
但是,这些示例非常简单,它们基本上只是展示了如何显示恰好是 Angular 的静态内容。
它们都没有展示如何处理 Angular2 应用使用的任何不映射到“真实”资源的 URL(我认为它们被称为路由)。
例如。我们在 Angular 应用程序中有一个“/login”路由,但我们没有 @Controller/@RequestMapping("/login") 用于此,我希望 Spring 在看到对“/”的请求时呈现 index.html登录”。
一般来说 - 我希望 Spring 在它不能成为实际资源时呈现“index.html”。有没有办法为所有无法映射或找到的请求设置默认视图?
我之前使用 htaccess 文件解决了这个问题,并让 apache 处理这个问题:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.html [L]
ErrorDocument 404 /index.html
</IfModule>
但在这种情况下我不能使用 apache 或 nginx。
【问题讨论】:
标签: angularjs spring spring-mvc single-page-application