Browser refresh not working, spring boot + React

Viewed 182

When we click on browser refresh it will return 403. I am trying to fix by using WebMvcConfigurer.addViewControllers(). We are using React and changing the url. for e.g.

In browser - http://localhost:8080/app/dashoboard. Actual call - http://localhost:8080/app/getDashboard

My code:

@Configuration
public class WebConfiguration implements WebMvcConfigurer {

    private static final String FORWARDINDEX = "forward:/index.html";
    private static final String FORWARDASHBOARD = "/getDashboard";
    
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // Map "/"
        registry.addViewController("/").setViewName(FORWARDINDEX);
        registry.addViewController("/dashboard").setViewName(FORWARDASHBOARD);

        registry.addViewController("/{x:[\\w\\-]+}").setViewName(FORWARDINDEX);
        
        registry.addViewController("/{x:^(?!api$).*$}/**/{y:[\\w\\-]+}").setViewName(FORWARDINDEX);
    }

In the above code "/" is working fine but "/dashboard" is not. We are using spring boot 2.4 and jwt. Any solution is welcome. We can also try with react.

0 Answers
Related