react使用react-router-config 進行路由配置

随心的博客發表於2024-09-18

1、新增路由配置檔案 routes.js

import { lazy } from "react";
export default [
    {
        path:'/admin',
        component:lazy(()=>import('./App.js')),
    },
]

2、App.js 中使用路由

import routes from './routes.js';
import { BrowserRouter } from "react-router-dom";
import { renderRoutes } from "react-router-config";

const App =()=>{
     return  <BrowserRouter>{renderRoutes(routes)}</BrowserRouter>
}
export default App;

  

相關文章