Spring catch all route for index.html

后端 未结 6 1914

I\'m developing a spring backend for a react-based single page application where I\'m using react-router for client-side routing.

Beside the index.html page the back

6条回答
  •  清酒与你
    2020-11-29 00:22

    Since my react app could use the root as forward target this ended up working for me

    @Configuration
    public class WebConfiguration extends WebMvcConfigurerAdapter {
    
      @Override
      public void addViewControllers(ViewControllerRegistry registry) {
          registry.addViewController("/{spring:\\w+}")
                .setViewName("forward:/");
          registry.addViewController("/**/{spring:\\w+}")
                .setViewName("forward:/");
          registry.addViewController("/{spring:\\w+}/**{spring:?!(\\.js|\\.css)$}")
                .setViewName("forward:/");
      }
    }
    

    To be honest I have no idea why it has to be exactly in this specific format to avoid infinite forwarding loop.

提交回复
热议问题