简体   繁体   English

反应路由器历史记录无法正确呈现

[英]React router history not render correctly

I'm using https://github.com/newtriks/generator-react-webpack to create an APP. 我正在使用https://github.com/newtriks/generator-react-webpack创建一个APP。

Everything is cool, I generate my dist files, but I upload my app on my website, like this: my-website.com/staging/my-app . 一切都很酷,我生成了dist文件,但是我将应用程序上传到了我的网站,例如: my-website.com/staging/my-app

But when I navigate to my-website.com/staging/my-app it renders the error component, and If I press Home button, I see the homepage as excepted but the url in the navbar is my-website.com/ . 但是,当我导航到my-website.com/staging/my-app时,它呈现了错误组件,如果按“主页”按钮,我会看到主页除外,但导航栏中的网址是my-website.com/

If your website doesn't located in the root url, you will need to provide a basename option 如果您的网站不在根网址中,则需要提供基本名称选项

For example: 例如:

import createBrowserHistory from "history/lib/createBrowserHistory"
import { Router, useRouterHistory } from "react-router"

const browserHistory = useRouterHistory(createBrowserHistory)({
  basename: "staging/my-app",
})

// component
<Router history={ browserHistory } routes={ routes } />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM