|
|
@@ -1,7 +1,7 @@
|
|
|
import React from 'react'
|
|
|
import { LocaleProvider } from 'antd'
|
|
|
import { Router, Route, Switch } from 'dva/router'
|
|
|
-import RootLayout from '../components/common/rootLayout'
|
|
|
+import PrivateRoute from './privateRoute'
|
|
|
import Login from '../components/common/login/login'
|
|
|
import Register from '../components/common/login/register'
|
|
|
import MainLayout from './mainLayout'
|
|
|
@@ -11,7 +11,7 @@ import DashboardDesigner from '../components/dashboardDesigner/layout'
|
|
|
import zhCN from 'antd/lib/locale-provider/zh_CN'
|
|
|
import Demo from '../demo';
|
|
|
import Xiaomi from '../xiaomi'
|
|
|
-import * as moment from 'moment'
|
|
|
+
|
|
|
|
|
|
function RouterConfig({ history }) {
|
|
|
return (
|
|
|
@@ -33,28 +33,4 @@ function RouterConfig({ history }) {
|
|
|
|
|
|
export default RouterConfig;
|
|
|
|
|
|
-const PrivateRoute = ({ component: Component, ...rest }) => (
|
|
|
- <Route
|
|
|
- {...rest}
|
|
|
- render={props =>{
|
|
|
-
|
|
|
- if (!window.localStorage.getItem('token')) {
|
|
|
- window.localStorage.setItem("token", "false");
|
|
|
- }else {
|
|
|
- /**
|
|
|
- * 是否过期
|
|
|
- * 1.是-----设置isAuthenticated为false
|
|
|
- */
|
|
|
- const t = moment(+window.localStorage.getItem('expireTime'));
|
|
|
- if(t.isValid() && t.diff(moment()) < 0) {
|
|
|
- window.localStorage.setItem("token", "false");
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- const isAuthenticated = window.localStorage.getItem('token') !== "false";
|
|
|
- return <RootLayout location={props.location} isAuthenticated={isAuthenticated}>
|
|
|
- <Component isAuthenticated={isAuthenticated} {...props} />
|
|
|
- </RootLayout>
|
|
|
- }}
|
|
|
- />
|
|
|
-);
|