0

当他从我的列表页面成功创建对象时,我试图将我的用户重定向到详细信息页面。这是我的代码:

历史.js

import {createHashHistory} from 'history';
const history = createHashHistory();   
export default history

应用程序.js

    class App extends Component {

  render() {    

        return (
          <Router history={history}>
            <Alerts/>
            <Switch>
                <PrivateRoute exact path="/" component={Main}/>
                <Route path="/login" component={Login}/>
            </Switch>
          </Router>
        )

  }
}

佐贺

export function* workerCreateTicket(action) {
...
...
yield call(forwardTo, `/tickets/${data.data.id}`); //<--- function to redirect if successful
...
}

function forwardTo(location) {
history.push(location);
}

预期的

我希望 URL 是这样的:

http://127.0.0.1:3000/tickets/14

结果 但是我收到了这个

http://127.0.0.1:3000/tickets#/tickets/14
4

2 回答 2

0

在容器中调用时,您可以尝试通过您的操作传递一个属性(历史)吗?=> workerCreateTicket(action) const { 历史 } = action;

于 2020-06-24T08:05:18.600 回答
0

它是关于createHashHistory。您使用hash-history,这意味着-lib 仅处理哈希 (#)之后history的部分 url 。

您可以将其切换为createBrowserHistory,它处理整个url。

于 2020-06-24T07:20:02.390 回答