为什么都没了

This commit is contained in:
路 范
2021-09-24 12:59:34 +08:00
parent a975b3bdee
commit a66921f0f4
962 changed files with 252792 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
import Main from '../views/main'
import Login from '../views/login'
import Error404 from '../views/error/404'
var routes = [
{ path: '/', name: 'main', component: Main, auth: true },
{ path: '/login', name: 'login', component: Login },
{ path: '/404', name: '404', component: Error404 }
]
// auth 是否需要登录
export default routes;

View File

@@ -0,0 +1,16 @@
import React from 'react';
import { Switch, BrowserRouter } from 'react-router-dom'
import NavigationGuards from './navigationGuards'
import RouterConfig from './config'
const router = () => {
return (
<BrowserRouter>
<Switch>
<NavigationGuards routerConfig={RouterConfig} />
</Switch>
</BrowserRouter>
)
}
export default router

View File

@@ -0,0 +1,26 @@
import React, { Component } from 'react'
import { Route, Redirect } from 'react-router-dom'
import { token } from '../common/token'
export default class navigationGuards extends Component {
render() {
const { routerConfig, location } = this.props
const { pathname } = location
const targetRouterConfig = routerConfig.find((item) => {
return item.path.replace(/\s*/g, '') === pathname
})
if (token.value) {
if (pathname === '/login') {
return <Redirect to='/' push={false} />
}
} else if (!token.value && pathname !== '/login') {
return <Redirect to='/login' push={false} />
}
const { component } = targetRouterConfig;
return <Route exact path={pathname} component={component} />
}
}