MYW
2 years ago
3 changed files with 31 additions and 69 deletions
@ -1,29 +1,12 @@ |
|||
import React from "react" |
|||
import { BrowserRouter, Routes, Route } from 'react-router-dom' |
|||
import RouterView from "./router/index" |
|||
import config from './router/config' |
|||
|
|||
// import Login from "./pages/login/Login"
|
|||
|
|||
import React from 'react'; |
|||
import Router from './router/index'; |
|||
|
|||
function App() { |
|||
return ( |
|||
// <div className="App">
|
|||
// <BrowserRouter>
|
|||
// <RouterView routes={config}></RouterView>
|
|||
// </BrowserRouter>
|
|||
// </div>
|
|||
|
|||
<RouterView/> |
|||
|
|||
// <div>
|
|||
// <BrowserRouter>
|
|||
// <Routes>
|
|||
// <Route path='login' element={<Login />}></Route>
|
|||
// </Routes>
|
|||
// </BrowserRouter>
|
|||
// </div>
|
|||
) |
|||
<div className="App"> |
|||
<Router /> |
|||
</div> |
|||
); |
|||
} |
|||
|
|||
export default App |
|||
export default App; |
@ -1,45 +1,24 @@ |
|||
import React, {Suspense} from "react"; |
|||
import { Redirect, Route, Switch } from 'react-router-dom' |
|||
import routes from './config' |
|||
import React from 'react'; |
|||
import routes from "./routes"; |
|||
import { BrowserRouter, Route, Routes } from "react-router-dom"; |
|||
|
|||
const RouterView = () => { |
|||
// const { routes } = props
|
|||
// console.log(routes)
|
|||
|
|||
return <Suspense fallback="loading"> |
|||
<Switch> |
|||
{ |
|||
routes.map(route => { |
|||
if (route.redirect) { |
|||
return <Route key={route.path} |
|||
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> |
|||
} |
|||
function router() { |
|||
return ( |
|||
<BrowserRouter> |
|||
<Routes> |
|||
{routes.map((item) => { |
|||
return ( |
|||
<Route |
|||
key={item.id} |
|||
path={item.path} |
|||
element={<item.component/>} |
|||
/> |
|||
); |
|||
})} |
|||
</Switch> |
|||
</Suspense> |
|||
|
|||
|
|||
// routes.map((item, index) => {
|
|||
// return (
|
|||
// <Routes key={item.id}>
|
|||
// <Route key={index} path={item.path} />
|
|||
// </Routes>
|
|||
// )
|
|||
// })
|
|||
</Routes> |
|||
</BrowserRouter> |
|||
); |
|||
} |
|||
|
|||
export default RouterView |
|||
|
|||
{/* <Routes key={item.id}></Routes> */ } |
|||
export default router; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue