Sagarkumar Unhale
Sagarkumar Unhale

Reputation: 51

React router is not working with webpack server and redux?

I have created below component,

const RouterComponent = () => (
 <Provider store={store}>
<Router>
  <Switch>
    <Route path="/" component={Body} />
    <Route exact path="success" component={SuccessPageComponent} />
  </Switch>
</Router>
);

export default RouterComponent;

I am rendering this component on my index.js so the default page is loading but if I am using '/success' with url and hit the page, it is not redirecting to the given SuccessPageComponent... I am using the public path as (const publicPath = path.join('/', '<service_name>', '/');) in my webpack.config file, does that creating a problem?

Upvotes: 1

Views: 179

Answers (1)

TalOrlanczyk
TalOrlanczyk

Reputation: 1213

when you use only path the Body component it will render in every route you go because Backslash will be in every Route now for the SuccessPageComponent I put Backslash before any route try it maybe

 <Switch>
    <Route exact path="/" component={Body} />
    <Route path="/success" component={SuccessPageComponent} />
  </Switch>

in the start I use it a lot but if you look you need to add Backslash or you go to position of 404 page that you can create by do this:

<Route component={NoFound} />

like this you can create 404 page react-router-doom doc

Upvotes: 1

Related Questions