Moving from react router 3.x to 4.x

后端 未结 5 513
悲&欢浪女
悲&欢浪女 2020-12-08 16:05

How can I move to using https://cdnjs.cloudflare.com/ajax/libs/react-router/4.0.0-2/react-router.min.js from using https://cdnjs.cloudflare.com/ajax/libs/

5条回答
  •  离开以前
    2020-12-08 16:36

    This is a supplement answer to the one Paul S posted above. Credit should still goto paul for posting it.

    Reason m supplementing the answer is bcoz:-

    1. I got errors with BrowserHistory and Link.
    2. I had to include react-router-dom.
    3. was a typo (in Pauls original answer)

    yarn steps:

    yarn add react-router
    yarn add react-router-dom
    

    package.json:

     "react": "^15.6.1",
        "react-dom": "^15.6.1",
        "react-router": "^4.1.1",
        "react-router-dom": "^4.1.1"
    

    index.js:

    import React from 'react';
    import ReactDOM from 'react-dom';
    import { Switch, Redirect, Route} from 'react-router';
    import {BrowserRouter, Link} from 'react-router-dom';
    
    
    //let { BrowserRouter, Switch, Redirect, Route, Link } = ReactRouter;
    
    const Main = () =>
      
        
          
            
            
            
            
            
          
        
      
    
    const App = props =>
      
    Map Settings Foo {props.children}
    const Navigation = props =>

提交回复
热议问题