dyong
dyong

Reputation: 35

React routing with spring mvc

I'm making an webapp using react and spring mvc. I've got 2 questions while making it.

  1. How do you request mapping? I want to map all the uris but resources and apis into index.jsp, react SPA entry.

    • resouce uris start with /res
    • api uris start with /api
  2. How do you response url that react recognize. I mean If you put /examples/1 on your browser, then the web server retutns index.jsp with uri /examples/1 so that react redirects itself to /examples/1.

Thanks.

Upvotes: 1

Views: 3934

Answers (1)

dyong
dyong

Reputation: 35

I've made a controller like this,

@RequestMapping("/api/**")
public ApiResult api(HttpServletRequest request, HttpServletResponse response){
    return apiProxy.proxy(request, reponse);
}

@RequestMapping(value="/**", method=HTTPMethod.GET)
public String index(){
    return "index"
}

and setup spring config like this.

<mvc:resource mapping="/res/**" location="/res/" order="-1"/>

order -1 is very important. It makes spring to check first the request url matches with resource mapping.

Upvotes: 2

Related Questions