Skip to content

Commit 5b73f36

Browse files
Merge pull request #40 from tusharkhatriofficial/dev
fix: add SPA forwarding controller for React Router
2 parents 028be56 + e24bdbe commit 5b73f36

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.eventara.config;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
6+
/**
7+
* Forwards all non-API, non-static-resource requests to index.html
8+
* so that React Router can handle client-side routing.
9+
*
10+
* Without this, navigating directly to /settings or /rules in the browser
11+
* would return a Spring Boot 404 instead of loading the SPA.
12+
*/
13+
@Controller
14+
public class SpaForwardingController {
15+
16+
@GetMapping(value = {
17+
"/",
18+
"/{path:^(?!api|ws|swagger|v3|webjars|static|assets|favicon\\.ico).*$}/**"
19+
})
20+
public String forward() {
21+
return "forward:/index.html";
22+
}
23+
}

0 commit comments

Comments
 (0)