I have implemented createBrowserHisotry according to this post How to get history on react-router v4?, however it only redirects if I set a configuration property to forceRefresh: true. If I do not set any config properties, the url changes to the pushed url but the page will not redirect. Why?
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./components/App";
import { Router } from 'react-router-dom'
import registerServiceWorker from "./registerServiceWorker";
import history from "./components/common/History";
ReactDOM.render(<Router history={history}><App /></Router>,
document.getElementById('root'));
registerServiceWorker();
import createBrowserHistory from 'history/createBrowserHistory';
// export default createBrowserHistory(); --> This redirects the ### ### URL
// but does not physically redirect
export default createBrowserHistory({
//pass a configuration object here if needed
forceRefresh: true
});
class App extends Component {
render() {
return (
<Provider store={store}>
<OidcProvider store={store} userManager={userManager}>
<Router>
<div className="container-fluid">
<div>
<Header />
</div>
<div>
<Route exact path="/" render={props => <LoginForm auth={this.auth} {...props} />} />
<Route exact path="/callback" render={props => <Callback auth={this.auth} {...props} />} />
<Route exact path="/home" render={props => <HomePage {...props} />} />
<Route exact path="/table" render={props => <TableContainer {...props} />} />
<Route exact path="/form/:id" render={props => <FormContainer id={this.props.params.id} {...props} />} />
<Route exact path="/form" render={props => <FormContainer {...props} />} />
</div>
<Footer />
</div>
</Router>
</OidcProvider>
</Provider>
);
}
}
export default App;
import history from "../components/common/History";
class CallbackPage extends React.Component {
render() {
// just redirect to '/' in both cases
return (
<CallbackComponent
userManager={userManager}
successCallback={() => history.push("/home")}
errorCallback={error => {
history.push("/");
console.error(error);
}}
>
<div>Redirecting...</div>
</CallbackComponent>
);
}
}
export default connect()(CallbackPage);
Use this:
this.props.history.push('/index');
this.props.history.go();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With