我在React js中创建了一个应用程序。在开发模式下一切正常,但在使构建路由无法正常工作之后。
我的package.json文件代码
{ "homepage": "http://localhost/hositng/react/",
"private": true,
"entry": {
"index": "./index.js"
},
}
我的路线文件代码
const Routes = () => (
<BrowserRouter basename="http://localhost/hositng/react" >
<Switch>
<Route exact path='/' component={Login} />
<Route path='/login' component={Login} />
<Route path='/home' component={Home} />
<Route path='/contact' component={Contact} />
</Switch>
</BrowserRouter>);
反应构建命令后,当我点击“http://localhost/hositng/react/”网址
但是当我刷新浏览器“http://localhost/contact”时,这个url空白页面即将到来
Switch中定义的路由看起来很好。我用它并且它有效。我建议在basename属性中使用相对路径而不是绝对路径。
<BrowserRouter basename="/hositng/react" >
有关它的更多信息BrowserRouter doc