在使用react js web应用程序构建之后,路由不是

问题描述 投票:0回答:1

我在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/”网址

  1. 它应该进入登录页面,但它将转到主页
  2. 当点击conact我们页面链接时,它将转到联系人页面网址正在变化。 它应该去这个网址“http://localhost/hositng/react/contact”,但它会去“http://localhost/contact”这个网址

但是当我刷新浏览器“http://localhost/contact”时,这个url空白页面即将到来

reactjs react-redux react-router
1个回答
0
投票

Switch中定义的路由看起来很好。我用它并且它有效。我建议在basename属性中使用相对路径而不是绝对路径。

<BrowserRouter basename="/hositng/react" >

有关它的更多信息BrowserRouter doc

© www.soinside.com 2019 - 2024. All rights reserved.