我被这个曲线球主要困住了 .
我有一个网站 Build w / create react app 我用 React Router. 打了一个拦截器
我理解GitHub页面可以完美地使用静态内容,但是:
1- what is the correct solution to deploy to GitHub pages with SPA using react router ?
我尝试了所有类型的配置,没有一个工作 .
我的路由配置为:
Index.js
import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter as Router } from "react-router-dom";
import App from './App';
render(<Router basename={process.env.PUBLIC_URL}><App /></Router>,
document.getElementById('root'));
Routes.js
import { Route, Switch, Redirect, HashRouter } from 'react-router-dom';
...
const Routes = () => (
<Switch>
<Route path='/' exact component={Home} />
<Route path='/contact' exact component={Contact} />
<Route path='/about/faculty' exact component={Faculty} />
<Route path='/about/what-we-do' exact component={Mission} />
<Redirect from='/about/' to='/about/faculty' />
<Route component={NotFound} />
</Switch>
)
export default Routes;
我尝试用 <HashRouter/>
包装我的 <Switch/>
,但这使得路线不再起作用 .
My Package.json
{
"name": "my-site",
"version": "0.1.0",
"private": true,
"homepage": "https://username.github.io/project_name",
"dependencies": {
...
"react-router": "4.2.0",
"react-router-bootstrap": "0.24.4",
"react-router-dom": "4.2.2",
"react-scripts": "1.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
"devDependencies": {
"gh-pages": "^1.1.0"
}
}
发布 yarn build
和 yarn run deploy
后,该网站会发布到此页面,该页面根本不包含任何内容,当然我尝试点击的任何路径都会给我一个 404.
2- Regarding the package.json what is the correct config for the homepage?:
"homepage": "https://username.github.io/project_name"
或 "homepage": "https://username.github.io"
作为最终结果,我希望该网站在 https://username.github.io
URL下提供服务,所以我对正确的配置感到困惑 .
3 - 我阅读了文档,声明我应该在 gh pages branch
下部署,而这实际上并没有显示在我的GitHub上 . 我只能选择发布到master .