Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In React:Module not found: Can't resolve 'react-router-dom'

enter image description here enter image description here

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

like image 230
cc shen Avatar asked Aug 07 '18 10:08

cc shen


1 Answers

The Router have to installed, I solved with the installation using the following command:

npm i react-router-dom --save
like image 171
DAme Avatar answered Oct 02 '22 07:10

DAme