react router v^4.0.0 Uncaught TypeError: Cannot read property 'location' of undefined

前端 未结 4 1598
没有蜡笔的小新
没有蜡笔的小新 2020-12-12 15:57

I\'ve been having some trouble with react router (i\'m using version^4.0.0).

this is my index.js

import React from \'react\';
import ReactDOM from \'         


        
4条回答
  •  孤街浪徒
    2020-12-12 16:43

    I've tried everything suggested here but didn't work for me. So in case I can help anyone with a similar issue, every single tutorial I've checked is not updated to work with version 4.

    Here is what I've done to make it work

    import React from 'react';
    import App from './App';
    
    import ReactDOM from 'react-dom';
    import {
        HashRouter,
        Route
    } from 'react-router-dom';
    
    
     ReactDOM.render((
            
                
    }/>
    ), document.getElementById('root'));

    That's the only way I have managed to make it work without any errors or warnings.

    In case you want to pass props to your component for me the easiest way is this one:

     }/>
    

提交回复
热议问题