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

前端 未结 4 1590
没有蜡笔的小新
没有蜡笔的小新 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:32

    so if you need want use this code )

    `import { useRoutes } from "./routes";
    
    import { BrowserRouter as Router } from react-router-dom";
    
    export const App = () => {`
    
    const routes = useRoutes(true);`
    
      return (
    
        
    
          
    {routes}
    ); };

    // ----

    import { Switch, Route, Redirect } from "react-router-dom";
    
    export const useRoutes = (isAuthenticated) => {
      if (isAuthenticated) {
        return (
          
            
              
            
            
              
            
            
              
            
            
          
        );
      }
      return (
        
          
            
          
          
        
      );
    };
    

提交回复
热议问题