I'm creating Spring Boot app using React on frontend side. I can open the page in a browser, but on backend side appears error:
RequestRejectedException: The request was rejected because the URL contained a potentially malicious String "//"
So I have a simple java-view controller:
@Controller
public class ViewController {
@RequestMapping("/")
public String index() {
return "index";
}
}
It returns html:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" http-equiv="CONTENT-TYPE" content="text/html; charset=UTF-8"/>
<title>Hello demo</title>
<link href="/build/react_app.css" rel="stylesheet"></head>
<body>
<div id="react"></div>
<script src="/build/js/main.min.js"></script><script src="/build/js/react_app.min.js"></script></body>
</html>
So in react app I connected react-router and here is my index.js:
const middleware = [thunk, createLogger()];
let container = document.getElementById('react');
const store = createStore(
reducer,
compose(applyMiddleware(...middleware))
);
ReactDOM.render(
<Provider store={store}>
<Router history={hashHistory}>
<Switch>
<Route exact path="/" component={MainPage}/>
<Route exact path="/login" component={LoginPage}/>
<Route exact path="/registration" component={RegistryPage}/>
<Route path="*" component={NotFound}/>
</Switch>
</Router>
</Provider>,
container
);
export default store;
So basically I can access main page, it renders ok. I can switch between routes, but in the same time on backend I see error. I debugged and realized why it happens. url of main page is
http://localhost:8080/#/
If I use url http://localhost:8080/#
it's ok, and no exceptions. How can I fix this? If I remove one of these slashes doesn't work properly