带有弹出引导路由URL的Angular 4,不使用哈希码

时间:2017-08-04 07:25:56

标签: spring angular spring-boot

以下是我的情景:

  1. 我正在使用带有Angular 4的Spring启动
  2. 我使用angular-cli生成构建文件并放置在资源 - 静态文件夹下。
  3. 在运行我的pom.xml时,所有静态文件夹都在目标下复制 - >项目文件夹 - > WEB-INF - >课程 - >静态文件夹(预期)
  4. 塞纳里奥:

    我的网址将是

    https://localhost:9443/consumer https://localhost:9443/consumer/preapproval https://localhost:9443/consumer/preapproval/申请人 https://localhost:9443/consumer/preapproval/客户端

    每次点击整个/整个网址都不会改变。如果我使用以下配置:

    `@Configuration 公共类WebConfig扩展了WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
    }
    
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/index.html");
    }
    
    @Bean
    public InternalResourceViewResolver defaultViewResolver() {
        return new InternalResourceViewResolver();
    }
    

    }`

    在spring boot中,当我刷新/输入(https://localhost:9443/consumer)以外的任何URL时,它会抛出404错误。任何人都可以建议我最好的解决方案。

    注意:在我的业务中,我们不应该在Angular 4中使用hashcode。

    提前致谢

1 个答案:

答案 0 :(得分:0)

我在项目中设置了一个类似于下面的getMapping。

@GetMapping("/{path:[^\\.]*}")
String redirect() {
    return "forward:/";
}