【问题标题】:ReactJS - Problem of URL when redirect page in mode buildReactJS - 在模式构建中重定向页面时出现 URL 问题
【发布时间】:2019-06-07 22:53:27
【问题描述】:

我是 react 新手。 我使用 npm run-script build 在 wamp 服务器中部署了一个 react-app 位置是:http://localhost/react-app

我的登录网址是:http://localhost/react-app/#/login

登录后,我将页面重定向到'/' 这是代码:

<Redirect to={{ pathname: '/', state: { from: props.location } }} />

网址变为:http://localhost/#/ 但是我想要http://localhost/react-app/#/

最好的方法是什么? 谢谢

【问题讨论】:

标签: reactjs redirect webpack build wamp


【解决方案1】:

阿尔法。 您可以像这样编写您的项目:

var projectName = "react-app"
import { browserHistory } from 'react-router';

<Router history={browserHistory}>
    <Redirect to={{ pathname: `/${projectName}/`, state: { from: props.location } }} />
</Router>

如果您需要更改项目名称,使用此模式很容易做到这一点。 我使用了我们称之为模板字符串或模板文字的东西,check here

顺便说一下,我通常会创建 api 文件夹,其中包含所有重要的后端配置以随时用作示例。

import api './../somefolder'
import { browserHistory } from 'react-router';

<Router history={browserHistory}>
    <Redirect to={{ pathname: `/${projectName}/`, state: { from: props.location } }} />
</Router>

你能试试这个并检查它是否有效吗?

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-28
  • 2019-12-30
  • 2021-07-04
  • 2016-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多