使用 redux-simple-router 导航到另一条路径

Navigate to another path with redux-simple-router

本文关键字:一条 一条路 路径 redux-simple-router 导航 使用      更新时间:2023-09-26

我正在尝试使用 redux-simple-router 导航到另一条路径。这是我的组件片段(请参阅handleSubmit方法):

import React, { Component } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import * as actionCreators from 'redux-simple-router'
@connect(
  state => state,
  dispatch => bindActionCreators(actionCreators, dispatch)
)
export class Header extends Component {
  constructor(props) {
    super(props)
    this.handleSubmit = this.handleSubmit.bind(this)
  }
  handleSubmit (e) {
    e.preventDefault()
    this.props.pushPath('/#/admin/users' + (this.state.searchInput !== '' ? '?query=' + this.state.searchInput : '') )
  }
  ...
}

这不是将我带到指定的路径,而是UPDATE_PATH调度 2 到 4 次,然后刷新页面并将我带到http://localhost:3000/?#/home。我错过了什么?导航到页面的正确方法是什么?网络上是否有对事件进行页面导航的示例?

我没有看到很多pushPath的例子。为什么不使用路由器?

handleSubmit (e) {
    e.preventDefault()
    this.context.router.push('/admin/users' + (this.state.searchInput !== '' ? '?query=' + this.state.searchInput : '') + id);
}