当我点击我网站上的主页按钮时,网址从 https://duyhung03.github.io/e-shop/ 更改为 https://duyhung03.github.io 即使我添加了 'basename '属性为'BrowserRouter'。这使我的站点重定向到 github 的 404 页面。请问我该如何解决?
index.js 文件
import React from 'react';
import ReactDOM from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import App from './App';
import GlobalStyles from './components/GlobalStyles';
const root = ReactDOM.createRoot(
document.getElementById('root'),
);
root.render(
<BrowserRouter basename={process.env.PUBLIC_URL}>
<GlobalStyles>
<App />
</GlobalStyles>
</BrowserRouter>,
);
package.json 文件
{
"name": "e-shop",
"homepage": "https://duyhung03.github.io/e-shop/",
"version": "0.1.0",
"private": false,
"dependencies": {
...
"gh-pages": "^5.0.0",
"number-to-words": "^1.2.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.4",
"react-scripts": "5.0.1",
"tippy.js": "^6.3.7",
"validator": "^13.9.0",
"web-vitals": "^2.1.4"
},
"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": {
"classnames": "^2.3.2",
"react-router-dom": "^6.10.0",
"sass": "^1.58.3",
"yarn": "^1.22.19"
}
}