react build后直接从浏览器打开

存在两个问题react

一,资源文件路径react-router

config/paths.jsapp

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

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

由此,背景图片的地址多是url

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

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

解决方案:code

routes/index.jsrouter

把原来的blog

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

改为:图片

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

就能够了

固然开发的时候,最好BrowserRouter

相关文章
相关标签/搜索