Reputation: 225
import * as React from 'react';
import Root from './Root';
import './App.css'
import {session} from './libs/session';
import {Redirect} from "react-router-dom";
export default class App extends React.Component {
public componentWillMount() {
console.log("componentWillMount App");
}
public componentDidMount() {
console.log("componentDidMount App");
console.log(window.location.search.replace(/\?/g,''));
const urlParmes = window.location.search.replace(/\?/g,'');
session.token = urlParmes.replace(/^token=/g,'');
}
public render() {
if (session.token === '' || session.token === null || session.token === 'undefined') {
console.log('no Jurisdiction');
return (<Redirect to='/'/>);
} else {
console.log('has Jurisdiction')
}
return (
<div className="App">
<Root />
</div>
)
}
}
My purpose is to detect 'token' and then redirect it to the login page. this is why? please help me. Thanks
Upvotes: 11
Views: 54161
Reputation: 727
The Router must be installed, I solved with the installation using the following command:
npm i react-router-dom --save
Upvotes: 20
Reputation: 406
cd in app working directory and then run: npm install @reach/router
Upvotes: -5
Reputation: 111
If you have installed the react-router-dom
package then you need Typescript definitions for react-router-dom. Install @types/react-router-dom
package. So either:
npm install @types/react-router-dom --save
or:
yarn add @types/react-router-dom
Upvotes: 11
Reputation: 5
From the react router docs it seems Redirect is part of react-router import { Route, Redirect } from 'react-router'
Upvotes: -3