Below is my index.js file,it contains the routing path to all the components.When I navigated to one component from another how can I retrieve the previous and current paths ?
import React from 'react';
import ReactDom from 'react-dom';
import Login from './testApp/login.js';
import Register from './testApp/register.js';
import { BrowserRouter as Router, Route} from "react-router-dom";
import fetch from 'isomorphic-fetch';
class App extends React.Component {
"eqeqeq":false;
constructor(props) {
super(props);
this.handleSubmit=this.handleSubmit.bind(this);
this.handleTest=this.handleTest.bind(this);
this.state={name:{}};
}
Greeting() {
return <h1>ffgdf</h1>
}
httpCalling(data) {
fetch('http://localhost:8080/testingonly', {
method:'POST',
mode:'CORS',
body:JSON.stringify(data),
headers:{
'Content-Type':'application/json',
'Accept': 'application/json'
}
}).then(res => res.json()).then(result => {
localStorage.setItem('myData',JSON.stringify(result));
});
const item=localStorage.getItem('myData');
console.log(JSON.parse(item));
}
handleSubmit(data) {
console.log("++++data++++++++");
console.log(data);
console.log("++++data++++++++");
this.httpCalling(data);
}
render() {
return (
<Router>
<div>
<Route exact path="/" render={(props) => <Login onSubmit={this.handleSubmit} {...props} />}/>
{/* add the routes here */}
<Route path="/test" component={this.Greeting}/>
<Route path="/register" render={(props) => <Register />} />
</div>
</Router>
)
}
}
ReactDom.render(<App />,document.getElementById('root'));
In the above example you can see that all components are defined in the render function of App component.So when I navigated from one component to another how can I detect the previos and current routes ?