哈希路由器和浏览器路由器出错。女巫 gh-pages

时间:2021-07-14 12:49:28

标签: reactjs github-pages

我正在使用 BrowserRouter 在 GH-PAGES 中部署页面,它向我显示了空白页面。但是当我使用 hashRouter 时,它确实如此。但是我使用路由器哈希的路由是 username.github.io / # / ... 事实是我正在使用 fullpage.js 并且每次我滚动它时都会将 url 更改为 #About、#Project 等。如果我使用哈希路由器,它不会跳转到#About,而是将我重定向到/关于,这是另一个页面。 我想使用浏览器路由器发布我的网站。有什么解决办法?

<ReactFullpage
                scrollingSpeed={1150}
                recordHistory={true}
                anchors={['#Home', '#About', '#Project', '#Contact']}
                navigation
                render={() => {
                    return (
                        <>
                            <div className='section' data-anchors='section1'>
                                <Home />
                            </div>
                            <div className='section' data-anchors='section2'>
                                <About />
                            </div>
                            <div className='section' data-anchors='section3'>
                                <Project />
                            </div>
                            <div className='section' data-anchors='section4'>
                                <Contact />
                            </div>
                        </>
                    );
                }}

Package.json:
{
  "homepage": "https://myusername.github.io/portafoliov2",
  "name": "portafolio-v2",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@fullpage/react-fullpage": "^0.1.19",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "framer-motion": "^4.1.17",
    "react": "^17.0.2",
    "react-animated-css": "^1.2.1",
    "react-dom": "^17.0.2",
    "react-icons": "^4.2.0",
    "react-parallax-mousemove": "^1.1.0",
    "react-responsive-carousel": "^3.2.18",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.3",
    "react-scroll": "^1.8.2",
    "sass": "^1.34.1",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "gh-pages": "^3.2.3"
  }
}

0 个答案:

没有答案