1

I have read the onEnter not called in React-Router but I do not know how to fix my problem. I just want to check the login status and redirect

index.js

import indexRoutes from "routes/index.jsx";

    ReactDOM.render(
      <Router history={hist}>
        <Switch>
          {indexRoutes.map((prop, key) => {
            return <Route path={prop.path} component={prop.component} key={key} />;
          })}
        </Switch>
      </Router>,
      document.getElementById("root")
    );

How to change my code to this?

<Route exact path="/home" render={() => (
  isLoggedIn() ? (
    <Redirect to="/front"/>
  ) : (
    <Home />
  )
)}/>
Yang Yun
  • 241
  • 1
  • 2
  • 12

1 Answers1

1

You should rather not define this in your index.js.

I would recommend to add another class reference in your index.js and place the logic inside there.

Craws
  • 363
  • 1
  • 19