2

Below code snippet from index.js works fine to me when I want to route from static links on the page-

import React from 'react';
import ReactDOM from 'react-dom';
import LoginForm from './components/LoginForm/LoginForm';
import { Provider } from 'react-redux';
import store from './redux/store';
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom';
import Home from './components/Home.js'

ReactDOM.render(
  <Provider store={store}>
    <Router>
      <div>
        <h2>My Page</h2>
        <ul>
          <li><Link to={'/'}>LoginForm</Link></li>
          <li><Link to={'/home'}>Home</Link></li>
        </ul>
        <hr />

        <Switch>
          <Route exact path='/' component={LoginForm} />
          <Route exact path='/home' component={Home} />
        </Switch>
      </div>
    </Router>
  </Provider>,
  document.getElementById('root')

Is there away to route into another page inside the code, like ?

 updateStore(loggedIn){
    const action = {type:loggedIn};
    store.dispatch(action);
    if(loggedIn==='LOGGED_IN'){
       console.log("I am In");
      //route me into another page ??
    }else{
      console.log("I am out");
    }
  }
Shubham
  • 187
  • 1
  • 2
  • 15
  • you want to redirect to `/` after login? – Manoz Jul 20 '18 at 11:31
  • i want to redirect to /home after I login – Shubham Jul 20 '18 at 11:33