[英]Parcel/React App works in localhost but not on server
I have a Parcel/React App that I am attempting to launch to production.我有一个 Parcel/React 应用程序,我正尝试将其投入生产。 After testing, I see that my navigation no longer works on the server (404s).测试后,我发现我的导航不再在服务器上工作(404s)。
I'm using React Router like so:我正在像这样使用 React Router:
<Suspense fallback={<div>Loading...</div>}>
<Router primary={false}>
<Home path="/" />
<About path="/about" />
<Portfolio path="work" />
<Contact path="/contact" />
</Router>
</Suspense>
I added homepage to my package.json as suggested in another thread, but still no luck.我按照另一个线程中的建议将主页添加到我的 package.json 中,但仍然没有运气。
"homepage": "."
I don't have any experience with IIS manager or anything like that so I am hesitant to make any server changes there, especially since I have other websites on the same server.我对 IIS 管理器或类似的东西没有任何经验,所以我对在那里进行任何服务器更改犹豫不决,特别是因为我在同一台服务器上有其他网站。
Is there anything that can be done in the code/build to make this work on the server, or will it require IIS changes?是否可以在代码/构建中完成任何操作以使其在服务器上工作,或者是否需要更改 IIS?
Here is my package.json:这是我的 package.json:
{
"name": "ericbelldesigns",
"version": "1.0.0",
"description": "Eric Bell Designs 2020",
"main": "src/App.js",
"dependencies": {
"@frontendmasters/pet": "^1.0.3",
"@reach/router": "^1.3.1",
"anime": "^0.1.2",
"axios": "^0.19.2",
"bezier-easing": "^2.1.0",
"charming": "^3.0.1",
"gsap": "^2.1.3",
"gsap-react-plugin": "^1.0.2",
"imagesloaded": "^4.1.4",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-router-dom": "^5.1.2",
"three": "^0.106.2",
"three-obj-loader": "^1.1.3",
"three-orbit-controls": "^82.1.0"
},
"browserslist": [
"last 2 Chrome versions",
"last 2 ChromeAndroid versions",
"last 2 Firefox versions",
"last 2 FirefoxAndroid versions",
"last 2 Safari versions",
"last 2 iOS versions",
"last 2 Edge versions",
"last 2 Opera versions",
"last 2 OperaMobile versions"
],
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@babel/preset-react": "^7.8.3",
"animejs": "^3.1.0",
"babel-eslint": "^10.0.3",
"cross-env": "^5.2.1",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.3.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jsx-a11y": "^6.2.0",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^1.6.1",
"parcel-bundler": "^1.12.4",
"parcel-plugin-html-externals": "^0.1.2",
"postcss-modules": "^1.5.0",
"prettier": "^1.19.1",
"sass": "^1.26.0",
"threejs-controls": "^1.0.6"
},
"scripts": {
"dev": "parcel src/index.html",
"dev:mock": "cross-env PET_MOCK=mock npm run dev",
"format": "prettier --write \"src/**/*.{js,jsx}\"",
"lint": "eslint \"src/**/*.{js,jsx}\" --quiet",
"test": "echo \"Error: no test specified\" && exit 1",
"production": "parcel build src/index.html"
},
"externals": {
"/images/**/*": false
},
"author": "Eric Bell <eric@ericbelldesigns.com>",
"license": "Apache-2.0",
"keywords": []
}
如果您导入了BrowserRouter
更改为HashRouter
,看看是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.