Browse Source

project

dev
MYW 2 years ago
parent
commit
5c67f4efbb
  1. 31
      src/App.js
  2. 61
      src/router/index.js
  3. 6
      src/router/routes.js

31
src/App.js

@ -1,29 +1,12 @@
import React from "react" import React from 'react';
import { BrowserRouter, Routes, Route } from 'react-router-dom' import Router from './router/index';
import RouterView from "./router/index"
import config from './router/config'
// import Login from "./pages/login/Login"
function App() { function App() {
return ( return (
// <div className="App"> <div className="App">
// <BrowserRouter> <Router />
// <RouterView routes={config}></RouterView> </div>
// </BrowserRouter> );
// </div>
<RouterView/>
// <div>
// <BrowserRouter>
// <Routes>
// <Route path='login' element={<Login />}></Route>
// </Routes>
// </BrowserRouter>
// </div>
)
} }
export default App export default App;

61
src/router/index.js

@ -1,45 +1,24 @@
import React, {Suspense} from "react"; import React from 'react';
import { Redirect, Route, Switch } from 'react-router-dom' import routes from "./routes";
import routes from './config' import { BrowserRouter, Route, Routes } from "react-router-dom";
const RouterView = () => { function router() {
// const { routes } = props return (
// console.log(routes) <BrowserRouter>
<Routes>
return <Suspense fallback="loading"> {routes.map((item) => {
<Switch> return (
{ <Route
routes.map(route => { key={item.id}
if (route.redirect) { path={item.path}
return <Route key={route.path} element={<item.component/>}
path={route.path} />
exact={route.exact} );
>
<Redirect to={route.redirect}/>
</Route>
} else {
return <Route key={route.path}
path={route.path}
exact={route.exact}
component={route.component}
>
</Route>
}
})} })}
</Switch> </Routes>
</Suspense> </BrowserRouter>
);
}
// routes.map((item, index) => {
// return (
// <Routes key={item.id}>
// <Route key={index} path={item.path} />
// </Routes>
// )
// })
}
export default RouterView
{/* <Routes key={item.id}></Routes> */ } export default router;

src/router/config.js → src/router/routes.js

|||||||
100:0
Loading…
Cancel
Save