You should not use <Link> outside a

后端 未结 10 1693
既然无缘
既然无缘 2020-11-27 15:55

I\'m trying to set up react-router in an example application, and I\'m getting the following error:

You should not use  outside a 
         


        
10条回答
  •  無奈伤痛
    2020-11-27 16:14

    I kinda come up with this code :

    import React from 'react';
    import { render } from 'react-dom';
    
    // import componentns
    import Main from './components/Main';
    import PhotoGrid from './components/PhotoGrid';
    import Single from './components/Single';
    
    // import react router
    import { Router, Route, IndexRoute, BrowserRouter, browserHistory} from 'react-router-dom'
    
    class MainComponent extends React.Component {
      render() {
        return (
          
    ); } } render(, document.getElementById('root'));

    I think the error was because you were rendering the Main component, and the Main component didn't know anything about Router, so you have to render its father component.

提交回复
热议问题