我在springboot应用程序的类/ static / angularapp /中有一个角度应用程序。如果我尝试使用下面的网址访问angular应用,则可以正常工作
http://localhost:8080/springbootapp/angularapp/index.html
我在我的角度应用程序中使用哈希路由。当我单击index.html中的链接时,路由更改为
http://localhost:8080/springbootapp/angularapp/#/route1
没关系。但是当我尝试重新加载页面时,它无法正常工作,因为index.html不在http://localhost:8080/springbootap/angularapp/
上加载我想在每次点击http://localhost:8080/springbootap/angularapp/index.html时被重定向到http://localhost:8080/springbootap/angularapp/。我尝试在春季启动中添加资源处理程序,但这没有用。这是我的代码。
@Configuration
public class NewConfig extends WebMvcConfigurerAdapter {
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/","classpath:/static/angularapp/", "classpath:/public/" };
@Bean
public WebMvcConfigurer webMvcConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!registry.hasMappingForPattern("/webjars/**")) {
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
}
if (!registry.hasMappingForPattern("/**")) {
registry.addResourceHandler("/**").addResourceLocations(
CLASSPATH_RESOURCE_LOCATIONS);
}
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/angularapp").setViewName(
"forward:/angularapp/index.html");
}
};
}
}
每当击中http://localhost:8080/springbootap/angularapp/时,请帮助我将请求转发到angularapp内部的index.html。