The method of using js Code to Control Route Jump after React Router 4.0

now you need to implement a requirement in react. Every time a page requests a link / jump, you need to verify the current login status to the server. The function requesting the link is encapsulated in a tool called request.js (not a component). When authentication fails, you need to jump to the error page. You are required not to use window.location.href method, because parameters need to be passed but must not be exposed. HashHistory can achieve similar functions before version 4.0. So what are we going to do after version 4.0?

Mar.24,2021

use withRouter
withRouter high-level components, and provide history for you to use ~

import React from "react";
import {withRouter} from "react-router-dom";

class MyComponent extends React.Component {
.
myFunction () {
this.props.history.push ("/ some/Path");
}
.
}
export default withRouter (MyComponent);

that's all right

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7baed2-28679.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7baed2-28679.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?