Ana*_*and 4 spring-boot angular2-routing angular5
我有一个在 springboot 端口 8080 上运行的 Web 服务。当我点击下面的 url 时,它工作正常:
http://localhost:8080/app,我将 url 重定向到下面:
http://localhost:8080/myHome/home
现在当我刷新页面时,我收到 404
下面是我的 index.html 的内容:
<base href="/myHome">
Run Code Online (Sandbox Code Playgroud)
包.json:
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build --dev --deploy-url=\"/app/\"",
"test": "ng test",
"lint": "ng lint",
"e2e": "protractor"
},
Run Code Online (Sandbox Code Playgroud)
我曾尝试使用中提到的 LocationStrategy
Angular 2: 404 错误在我通过浏览器刷新时发生,但它对我不起作用。
mar*_*571 10
我在 spring boot 2 中遇到了同样的问题。我已将资源解析器位置添加为静态目录,如果与任何文件不匹配,则加载 index.html
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**/*")
.addResourceLocations("classpath:/static/")
.resourceChain(true)
.addResolver(new PathResourceResolver() {
@Override
protected Resource getResource(String resourcePath, Resource location) throws IOException {
Resource requestedResource = location.createRelative(resourcePath);
return requestedResource.exists() && requestedResource.isReadable() ? requestedResource : new ClassPathResource("/static/index.html");
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是由 spring 检查资源 /myHome/home 引起的错误,但没有找到
资源位置是 /app 所以你可以修复 -
1) Use hashRouting in angular application
Run Code Online (Sandbox Code Playgroud)
或者
2) Redirect to '/' in springboot aplication when requesting came from another url /**
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5515 次 |
| 最近记录: |