aa1547437877
aa1547437877
2018-11-22 11:18

react-router 属性exact 发布后失效

代码:

 import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
function Hello() {
return <div>hello</div>;
}
ReactDOM.render(
 <Router>
<Switch>
<Route exact path="/" component={Hello} />
<Route component={App} />
</Switch>
</Router>,
document.getElementById("root")
);

本地调试,在浏览器中访问首页是可以显示hello的,如下图
图片说明
但是npm run build后,访问就不行了,只能访问App,访问不到,如下图
图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

相关推荐