I want to redirect to home page after i clicked on a button in login page..But when i clicked the button in address bar ,home page's path is shown( it redirects to the home page)..but it doesn't render the component relevant to that path.It still shows the login page with home page address.So,i have to refresh the page to render the home page.what is wrong here???
In my login page...this is the function i used for the button onClick..
gotopage()
{
this.props.history.push('/home')
}
In my index,js page..
import React from "react";
import { render } from "react-dom";
import {BrowserRouter as Router,Route,Redirect ,browserHistory} from "react-router-dom";
import { Firstpage } from "./Firstpage";
import { Login } from "./Login";
import { Home } from "./Home";
import createBrowserHistory from 'history/createBrowserHistory'
const history=createBrowserHistory();
class App extends React.Component {
render(){
return(
<Router history={browserHistory}>
<div>
<switch>
<Route path="/" component={Firstpage} exact> </Route>
<Route path="/home" component={Home}> </Route>
<Route path="/login" render={(props) => <Login {...props} history=
{history} } />}> </Route>
</switch>
</div>
</Router>
);
}
}