我有一个项目,以 Spring Boot 作为后端,以 Angular 作为前端。 我打包的方式是,我构建 Angular 项目并将内容复制到 Spring Boot 资源文件夹中,并在我的 Spring Boot Controller 中返回由 Angular 生成的 index.html。
@Controller
public class IndexController {
@Autowired
ISupportedLanguagesRepository is;
@RequestMapping(value={ "/", ""})
public String getIndex() {
return "index.html";
}
}
所有其他 Controller 都是对后端的 REST api 调用。 当我分别运行 Spring Boot 和 Angular 项目时,所有路线都运行良好。
但是当我将它们打包在一起时,只有当所有导航都通过应用程序完成时,路线才起作用。但是当我直接尝试获取网址时,它给了我这个
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
但是当我从应用程序转到此路线时它会起作用。
如何解决这个问题?即使在任何页面上点击刷新也会出现相同的错误。
最佳答案
正如 Dirk 提到的,通过在路由中使用 {useHash: true} 可以解决这个问题
关于java - Angular Spring Boot 打包问题 Whitelabel 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53418696/