|
@@ -1,21 +1,41 @@
|
|
|
-import React from "react";
|
|
|
-import { Button } from "antd";
|
|
|
-import { BrowserRouter, Switch, Route } from "react-router-dom";
|
|
|
-import Home from "./pages/Home.tsx";
|
|
|
+import React from 'react';
|
|
|
|
|
|
-import "./app.less";
|
|
|
-import background from "./images/background.jpg";
|
|
|
+import { Switch, Route } from 'react-router-dom';
|
|
|
+import Home from './pages/Home/home.tsx';
|
|
|
+// import Other from './pages/other.tsx';
|
|
|
+
|
|
|
+import './app.less';
|
|
|
+import background from './images/background.jpg';
|
|
|
|
|
|
export default class App extends React.Component {
|
|
|
- test() {
|
|
|
- // body...
|
|
|
- console.log(12);
|
|
|
- }
|
|
|
- render() {
|
|
|
- return (
|
|
|
- <div>
|
|
|
- <Route path="/" component={Home} />
|
|
|
- </div>
|
|
|
- );
|
|
|
- }
|
|
|
+ tpl: Object[];
|
|
|
+ test(): any {
|
|
|
+ const requireComponents = require.context('./pages', true, /\.tsx$/);
|
|
|
+ let tpl: any[] = [];
|
|
|
+ requireComponents.keys().forEach((fileName) => {
|
|
|
+ const reqCom = requireComponents(fileName);
|
|
|
+ console.log(fileName);
|
|
|
+
|
|
|
+ const reqComName = fileName.replace(/^\..*\//, '').replace(/\.tsx$/, '');
|
|
|
+ tpl.push({
|
|
|
+ reqComName,
|
|
|
+ component: reqCom.default || reqCom,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ console.log(23, tpl[0].component);
|
|
|
+
|
|
|
+ return tpl;
|
|
|
+ }
|
|
|
+ render() {
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <Switch>
|
|
|
+ <Route exact path="/" component={Home} />
|
|
|
+ {this.test().map((key): any => (
|
|
|
+ <Route path={`/${key.reqComName}`} component={key.component} />
|
|
|
+ ))}
|
|
|
+ </Switch>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|