WiseOlMan
WiseOlMan

Reputation: 926

Can you go backwards through react-router v4 hashHistory?

Wondering how to go back to a previous route in a react web app using hashRouter instead of browserRouter in react-router v4?

I've found this question which doesn't seem to work even though it says no browser mixin needed (plus I think its talking about an older react-router version) however, every other solution I've seen depends on browserHistory.

Is it possible with hashHistory?

Upvotes: 1

Views: 5580

Answers (2)

ventro_art
ventro_art

Reputation: 624

Well in my case i did like that :

import withRouter from "react-router-dom/es/withRouter";
import React from "react";

class Component extends React.Component {
  goBack() {
    this.props.history.go(-1);
  }
  ...
}    
const WrappedComponent = withRouter(Component)
export default WrappedComponent;

withRouter give us access to history in props of component, but i'm not sure is this way is correct

Upvotes: 1

WiseOlMan
WiseOlMan

Reputation: 926

this.props.history.goBack()

Taken from the comments on this question

It is a function call.

Upvotes: 5

Related Questions