Skip to content

Commit

Permalink
feat: 重构
Browse files Browse the repository at this point in the history
  • Loading branch information
senwii committed Dec 31, 2019
1 parent 6ba8339 commit 5cfcfa8
Show file tree
Hide file tree
Showing 19 changed files with 222 additions and 311 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# react-template-project
> react模板项目
> React Template Project Integrated Github Actions
![ci action](https://github.com/senwii/react-template-project/workflows/ci/badge.svg)


技术栈:React Hooks + React Router DOM

特性:支持SPA/MPA

SPA页面结构参考`/src/pages/Index/`

新增MPA页面:`/src/pages/`目录下新建一个文件夹即可,参考`/src/pages/Index/`

访问页面:localhost:${port}${pathPrefix}${pageFolderName}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "NODE_ENV=develop webpack-dev-server",
"build:develop": "NODE_ENV=develop webpack",
"build": "NODE_ENV=product webpack"
"build": "NODE_ENV=production webpack"
},
"author": "senwii",
"homepage": "https://senii.github.io/react-template-project",
Expand Down
41 changes: 41 additions & 0 deletions public/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Single Page Apps for GitHub Pages</title>
<script type="text/javascript">
// Single Page Apps for GitHub Pages
// https://github.com/rafrex/spa-github-pages
// Copyright (c) 2016 Rafael Pedicini, licensed under the MIT License
// ----------------------------------------------------------------------
// This script takes the current url and converts the path and query
// string into just a query string, and then redirects the browser
// to the new url with only a query string and hash fragment,
// e.g. http://www.foo.tld/one/two?a=b&c=d#qwe, becomes
// http://www.foo.tld/?p=/one/two&q=a=b~and~c=d#qwe
// Note: this 404.html file must be at least 512 bytes for it to work
// with Internet Explorer (it is currently > 512 bytes)

// If you're creating a Project Pages site and NOT using a custom domain,
// then set segmentCount to 1 (enterprise users may need to set it to > 1).
// This way the code will only replace the route part of the path, and not
// the real directory in which the app resides, for example:
// https://username.github.io/repo-name/one/two?a=b&c=d#qwe becomes
// https://username.github.io/repo-name/?p=/one/two&q=a=b~and~c=d#qwe
// Otherwise, leave segmentCount as 0.
var segmentCount = 0;

var l = window.location;
l.replace(
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
l.pathname.split('/').slice(0, 1 + segmentCount).join('/') + '/?p=/' +
l.pathname.slice(1).split('/').slice(segmentCount).join('/').replace(/&/g, '~and~') +
(l.search ? '&q=' + l.search.slice(1).replace(/&/g, '~and~') : '') +
l.hash
);

</script>
</head>
<body>
</body>
</html>
31 changes: 31 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@
<title><%= title %></title>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<link rel="icon" href="https://senwii.github.io/react-template-project/assets/logo_64x64.png" type="img/x-ico" />
<!-- Start Single Page Apps for GitHub Pages -->
<script type="text/javascript">
// Single Page Apps for GitHub Pages
// https://github.com/rafrex/spa-github-pages
// Copyright (c) 2016 Rafael Pedicini, licensed under the MIT License
// ----------------------------------------------------------------------
// This script checks to see if a redirect is present in the query string
// and converts it back into the correct url and adds it to the
// browser's history using window.history.replaceState(...),
// which won't cause the browser to attempt to load the new url.
// When the single page app is loaded further down in this file,
// the correct url will be waiting in the browser's history for
// the single page app to route accordingly.
(function(l) {
if (l.search) {
var q = {};
l.search.slice(1).split('&').forEach(function(v) {
var a = v.split('=');
q[a[0]] = a.slice(1).join('=').replace(/~and~/g, '&');
});
if (q.p !== undefined) {
window.history.replaceState(null, null,
l.pathname.slice(0, -1) + (q.p || '') +
(q.q ? ('?' + q.q) : '') +
l.hash
);
}
}
}(window.location))
</script>
<!-- End Single Page Apps for GitHub Pages -->
</head>
<body>
<div id="app"></div>
Expand Down
32 changes: 32 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from "react"
import ReactDOM from 'react-dom'
import {
BrowserRouter,
Switch,
Route,
} from "react-router-dom"

import routes from './router'

function App() {
return (
<div className="root">
<BrowserRouter>
<Switch>
{
routes.map((route, index) => (
<Route path={ route.path } key={ index } render={ props => (
<route.component {...props} routes={route.routes} />
)} />
))
}
</Switch>
</BrowserRouter>
</div>
)
}

ReactDOM.render(
<App />,
document.getElementById('app'),
)
21 changes: 0 additions & 21 deletions src/pages/404/App.js

This file was deleted.

Binary file removed src/pages/404/assets/404_not_found.png
Binary file not shown.
Binary file removed src/pages/404/assets/logo.png
Binary file not shown.
28 changes: 0 additions & 28 deletions src/pages/404/style.less

This file was deleted.

38 changes: 0 additions & 38 deletions src/pages/Index/App.js

This file was deleted.

16 changes: 0 additions & 16 deletions src/pages/Index/style.less

This file was deleted.

7 changes: 0 additions & 7 deletions src/pages/Index/views/About.js

This file was deleted.

13 changes: 3 additions & 10 deletions src/pages/Index/router.js → src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@ import loadable from "@loadable/component"
const routes = [
{
path: '/hello',
component: loadable(() => import(/* webpackChunkName: "hello" */ './views/Hello')),
component: loadable(() => import(/* webpackChunkName: "hello" */ './views/Hello.jsx')),
},
{
path: '/about',
component: loadable(() => import(/* webpackChunkName: "about" */ './views/About')),
}
component: loadable(() => import(/* webpackChunkName: "about" */ './views/About.jsx')),
},
]

// set current pageName as base
const basename = `${process.env.PATH_PREFIX}Index`

export {
basename,
}

export default routes
7 changes: 7 additions & 0 deletions src/views/About.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react'

export default function About() {
return (
<div>This is the About page.</div>
)
}
File renamed without changes.
Loading

0 comments on commit 5cfcfa8

Please sign in to comment.