react build后直接从浏览器打开


存在两个问题

一,资源文件路径

config/paths.js

这里原来的.pathname:'/', 改成.pathname:'./'

function getServedPath(appPackageJson) {
  const publicUrl = getPublicUrl(appPackageJson);
  const servedUrl =
    envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : './');
  return ensureSlash(servedUrl, true);
}

由此,背景图片的地址可能是

.add-bank-sign {
    background: url("./../img/index.png"); //路径前面加'./'
}

二,当点击路由跳转的时候,会出现这样的报错

解决方案:

routes/index.js

把原来的

import { BrowserRouter as Router,Route, Switch, Redirect } from 'react-router-dom'

改成:

import { HashRouter as Router, Route, Switch, Redirect } from 'react-router-dom'

就可以了

当然开发的时候,最好BrowserRouter


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM