1549469775 4 years ago
parent
commit
0e3d8a628c
  1. 50
      src/AppRouter.tsx
  2. 10
      src/assets/style/common.scss
  3. 15
      src/route.tsx
  4. 10
      src/views/About/index.tsx
  5. 8
      src/views/Layout/index.tsx
  6. 9
      src/views/Login/Test.tsx
  7. 18
      src/views/Login/index.tsx

50
src/AppRouter.tsx

@ -6,30 +6,40 @@ import { pageList } from "@/plugins/pageHoc"
import Layout from "@/views/Layout" import Layout from "@/views/Layout"
import Auth from "@/ui/Auth" import Auth from "@/ui/Auth"
import routes from "./route" import routes,{Loading} from "./route"
function Wrapper(props: any) {
if (!props.isSub) {
return <React.Suspense fallback={<Loading></Loading>}>{props.children}</React.Suspense>
}
return <Fragment>{props.children}</Fragment>
}
function RouteMap(props: any) { function RouteMap(props: any) {
const routes: any[] = props.routes const routes: any[] = props.routes
const isSub: boolean = props.isSub
return ( return (
<Switch> <Wrapper isSub={isSub}>
{routes.map((route, index) => { <Switch>
const { exact = false } = route {routes.map((route, index) => {
if (route.redirect) { const { exact = false } = route
return ( if (route.redirect) {
<Route key={index} path={route.path} exact={exact}> return (
<Redirect to={route.redirect}></Redirect> <Route key={index} path={route.path} exact={exact}>
</Route> <Redirect to={route.redirect}></Redirect>
) </Route>
} )
if (route.component) { }
return ( if (route.component) {
<Auth key={index} needAuth={!!route.meta?.auth} path={route.path} exact={exact}> return (
<route.component meta={route.meta}>{route.children && <RouteMap routes={route.children}></RouteMap>}</route.component> <Auth key={index} needAuth={!!route.meta?.auth} path={route.path} exact={exact}>
</Auth> <route.component meta={route.meta}>{route.children && <RouteMap routes={route.children} isSub></RouteMap>}</route.component>
) </Auth>
} )
})} }
</Switch> })}
</Switch>
</Wrapper>
) )
} }

10
src/assets/style/common.scss

@ -9,11 +9,11 @@ textarea {
} }
body{ body{
background-image: url("@/assets/images/0.jpg"); // background-image: url("@/assets/images/0.jpg");
background-attachment: fixed; // background-attachment: fixed;
background-position: center top 36px; // background-position: center top 36px;
background-repeat: no-repeat; // background-repeat: no-repeat;
background-size: cover; // background-size: cover;
} }
a { a {
// color: initial; // color: initial;

15
src/route.tsx

@ -1,23 +1,28 @@
import Home from "@/views/Home" import Home from "@/views/Home"
import About from "@/views/About" import About from "@/views/About"
import Page404 from "@/views/Auth/Page404" import Page404 from "@/views/Auth/Page404"
import React from "react" import React, {lazy} from "react"
function Test() { function Test() {
return <div>TExtas</div> return <div>TExtas</div>
} }
export const Loading = ()=><div>Loding...</div>
export default [ export default [
{ {
path: "/about", path: "/about",
component: About, component: About,
meta: { meta: {
auth: true, auth: false,
}, },
children: [ children: [
{ {
path: "/about/test", path: "/about/test",
component: Test, meta: {
auth: false,
},
component: lazy(()=>import("@/views/Login/Test")),
}, },
], ],
}, },
@ -35,6 +40,10 @@ export default [
redirect: "/home", redirect: "/home",
}, },
{ {
path: "/login",
component: lazy(() => import("@/views/Login"))
},
{
path: "*", path: "*",
exact: false, exact: false,
component: Page404, component: Page404,

10
src/views/About/index.tsx

@ -1,13 +1,21 @@
import React from "react" import React from "react"
import { useLocation } from "react-router-dom" import { useLocation, Route, Switch } from "react-router-dom"
function Test() {
return <div>test</div>
}
export default function (props: any) { export default function (props: any) {
let location = useLocation() let location = useLocation()
console.log(location) console.log(location)
console.log(props)
return ( return (
<div className="container mx-auto"> <div className="container mx-auto">
<div>About</div> <div>About</div>
<div>22{props.children}</div> <div>22{props.children}</div>
<Route path="/about/aa" exact={true}>
<Test></Test>
</Route>
</div> </div>
) )
} }

8
src/views/Layout/index.tsx

@ -1,11 +1,11 @@
import React, { ReactElement } from "react" import React, { ReactElement } from "react"
import { useLocation } from "react-router-dom" import { useLocation } from "react-router-dom"
interface IProps { // interface IProps {
render(): ReactElement // render(): ReactElement
} // }
export default function (props: IProps) { export default function (props: any) {
return ( return (
<div> <div>
<div className="content"> <div className="content">

9
src/views/Login/Test.tsx

@ -0,0 +1,9 @@
import React from "react";
export default function(){
return (
<div>
saadsadsaddddddddddddddddd
</div>
)
}

18
src/views/Login/index.tsx

@ -0,0 +1,18 @@
import React from "react"
import { useLocation, Route, Switch } from "react-router-dom"
function Test() {
return <div>test</div>
}
export default function (props: any) {
let location = useLocation()
console.log(location)
console.log(props)
return (
<div className="container mx-auto">
<div>Login</div>
<div>22</div>
</div>
)
}
Loading…
Cancel
Save