Problem
When building my project for production with react, react-router V4 and webpack, the "Switch" is not rendering any matching routes. But it works in a development environment.
What I've tried
I used the boilerplate here : https://github.com/KleoPetroff/react-webpack-boilerplate
My Router.js is simply :
import React from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import App from '../components/App';
import About from '../components/About';
const Root = () => {
return (
<Router>
<Switch>
<Route path="/about" component={About} />
<Route exact path="/" component={App} />
</Switch>
</Router>
);
};
export default Root;
And the components App.js and About.js are simply :
App.jsimport React from 'react';
import { Link } from 'react-router-dom';
const App = () => {
return (
<h2 id="heading">
Hello ReactJS
<Link to="/about">here</Link>
</h2>
);
};
export default App;
About.js
import React from 'react';
const About = () => {
return (
<h2 id="heading">
About ReactJS
</h2>
);
};
export default About;
My Research
I went through plenty of stackoverflow's similar question (more related about react-router-redux apparently) but I got no working answers for the moment.
I tried to implement the app using different webpack configs like the one with react-create-app repo.
I'm not sure if it's related to the latest version of react-router or with my webpack config.
It sounds like a dumb and easy problem but I can't find answers anywhere in the web.
So my question is, how do I make the switch component match the correct paths ?