2

I am trying to catch all unconfigured routes once all other controllers have been checked and no route matches.

My controller is as below:

@Controller
public class ForwardController {

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

But this does not match : http://localhost:8080/abc/def

May I request some guidance on this?

My goal is to not have to handle /error and catch unconfigured routes which otherwise would lead to /error

I fixed this using:

@Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/**/{path:[^\\.]+}").setViewName("forward:/");
  }

The only issue now is that images are not rendering.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Kate
  • 21
  • 2
  • What is your goal so? Spring Mvc is built around an idea of mapping java controllers to well defined and non ambiguous paths. Maybe you need a servlet filter or even a servlet that will map to all the requests instead of spring mvc’s dispatcher servlet? – Mark Bramnik Aug 12 '20 at 20:47
  • I am referring to the solution proposed in https://stackoverflow.com/questions/24837715/spring-boot-with-angularjs-html5mode. I am trying to achieve this. – Kate Aug 12 '20 at 20:54

1 Answers1

0

Not sure about this. Just referring to: Spring catch all route for index.html

could you try adding this:

/{spring:\\w+}

to make the above:

@RequestMapping(value = "/{spring:\\w+}")
Tom Spencer
  • 34
  • 1
  • 4
  • It works well if the uri has a single segment. For ex: http://localhost:8080/home. But if I have multiple segments, http://localhost:8080/home/article, it fails. Could this be adapted to account for multiple segments? – Kate Aug 13 '20 at 10:59
  • Cool! Could you replace with: ```(value = "/**/{spring:\\w+}")``` – Tom Spencer Aug 13 '20 at 18:32