im当我的用户成功从我的列表页面创建对象时,尝试将其重定向到详细信息页面。这是我的代码:
history.js
import {createHashHistory} from 'history';
const history = createHashHistory();
export default history
app.js
class App extends Component {
render() {
return (
<Router history={history}>
<Alerts/>
<Switch>
<PrivateRoute exact path="/" component={Main}/>
<Route path="/login" component={Login}/>
</Switch>
</Router>
)
}
}
SAGA
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
答案 0 :(得分:0)
大约是createHashHistory
。您使用hash-history
,这意味着history
-lib仅在 哈希(#)之后处理URL的一部分。
您可以将其切换为createBrowserHistory
,它可以处理整个网址。
答案 1 :(得分:0)
在容器中调用时,您可以尝试通过操作传递属性(历史记录)吗? => workerCreateTicket(动作) const {history} = action;