score:1
To redirect the user you want to call push
on the history object. To get the history object in a class component you can use the withRouter higher-order component, e.g.
class Login extends Component {
render() {
const { history } = this.props;
return (
<div>
<button onClick={() => history.push('foo')}>Login</button>
</div>
);
}
}
export const LoginWithRouter = withRouter(Login);
Source: https://dev.to/kozakrisz/react-router---how-to-pass-history-object-to-a-component-3l0j
Source: stackoverflow.com
Related Query
- How to navigate from one component to another by clicking a button using React router
- How to pass a prop from one component to another when using react router link
- How can I pass props from one component to another using Link and router in react
- How to pass data from one component to another component in onchange using React js
- How to transfer data from one parent component to another parent component in react using router / router params
- How to set state in parent from one child component and access the state in another child component using react and typescript?
- How to pass value from one component to another using onClick in React
- How to pass json data from one component to another using functions in react
- How to pass props from one component to another using optional handling in react hooks
- How to update value got from a query on clicking a button in another component using react, typescript and graphql?
- How to navigate from one link to another inside same page using React URL hash or route?
- how to navigate from one page to another in react js?
- How to from one component set state another component in react native?
- How to pass data from one component to another in React or React-Redux?
- How to pass data from one component to another while using API in reactjs
- How to parse data through a button from one component to another
- How to refresh data of one component from another component in react js
- React - how to populate one select menu based on a value of another select menu using data from a local .json file
- In React, how do I call a function in one component (which is being rendered with React Router) from another component?
- I want to navigate to a page/component where I passed the data from another component using both React hooks and useHistory, but I get undefined
- React Router: How to navigate to another component using anchor tags
- How to set one component's state from another component in React
- How do I stop state store data from accumulating in a redux component every time I navigate to it using react router
- Error Coming when passing props from one component to another and vice - versa in react using typescript
- How to invoke one component action from other component Using React Hooks?
- Passing data from one component to another in React using formik
- how to pass the data from one component to another in react js
- How to pass state from one component to another in React js?
- In a react components, how to get latest data from state once it is changed from another component using redux?
- How to pass method from one component to another without using Arrow Function?
More Query from same tag
- Avoid function to run again and again in ReactJs
- react.js this2.setState is not a function
- How to count the number of Grandchildren
- Type 'undefined' cannot be used as an index type
- How to output datocms graphql query with an array inside multiple posts
- Typescript RefForwardingComponent not working
- No overload matches this call from react
- Could not find "store" in the context of "Connect(DiveLogTable)". Either wrap the root component in a <Provider> Error in Redux component
- can't return jsx in nested map react javascript
- Setting styles for react-slick
- Problem with passing props to child component
- Animation not working in ReactVR
- React - TypeError: Cannot read property 'smallThumbnail' of undefined
- How to return error with Express to front-end within a Promise?
- Mui5 Autocomplete warning
- How to test a range of numbers with Jest?
- React render link containing a variable
- how to show live server of react once closing command line
- Add dropdown to side navbar
- Is it a best practice to only supply props shallowly in React components?
- Rails project with React Rails directories?
- How can I construct a link to a "neighbour" resource in react router v6?
- Set correct height of React component after scaling with tailwindcss
- How to pass a state from component to a parent - the App.js (click outside to close navbar)
- React set background color with state rgb
- ReactJS, material-ui TextField onChange not working
- Unexpected token, expected "}" Error while passing object from FetchMovie to MovieList component at line 7 of MovieList.js
- Can't register serviceworker outside public folder react
- A component is changing controlled i/p to be uncontrolled. This is caused by value changing from defined to undefined Decide between using controlled/
- Type error when using render when defining table columns in material table React