Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React router push仅更改url_Reactjs_React Router - Fatal编程技术网

Reactjs React router push仅更改url

Reactjs React router push仅更改url,reactjs,react-router,Reactjs,React Router,我正在使用react路由器,我想通过单击一行重定向到详细页面 这是我的组件 <Table model={TypeModel} source={this.props.types} selectable={false} onRowClick={index => this.context.router.push(`/dashboard/types/${this.props.types[index].id}`)} /> 我不知道为什么,这是工作在其他地方的应用程序。我

我正在使用react路由器,我想通过单击一行重定向到详细页面

这是我的组件

<Table
  model={TypeModel}
  source={this.props.types}
  selectable={false}
  onRowClick={index => this.context.router.push(`/dashboard/types/${this.props.types[index].id}`)}
/>
我不知道为什么,这是工作在其他地方的应用程序。我也检查并尝试了这个线程

我错过什么了吗


更多细节 我的路由器看起来像

const routes = createRoutes(store)
<Router history={browserHistory} children={routes} />
export const TypeListRoute = store => ({
  getComponent (nextState, cb) {
    require.ensure([], (require) => {
      const Type = require('./containers/TypeContainer').default

      const reducer = require('./modules/type').default

      injectReducer(store, { key: 'type', reducer })

      cb(null, Type)
    }, 'type')
  }
})
仪表板布局
是一个react组件,它将子级封装到一些组件中

export class DashboardLayout extends React.Component {
  constructor (props) {
    super(props)
    this.children = props.children
  }

  render () {
    return ( 
      <Layout theme={drawerTheme}>
        <NavDrawer pinned >...</NavDrawer>
        <Panel>
          {this.children}
        </Panel>
      </Layout>
    )
  }
}
其中
TypeContainer
从“react工具箱”返回连接的(到redux存储)
表`

TypeDetailsRoute
完全相同,但我指定了一个路径

export const TypeDetailsRoute = store => ({
  path: ':id',
  getComponent (nextState, cb) {
    require.ensure([], (require) => {
      const Type = require('./containers/TypeDetailsContainer').default

      const reducer = require('./modules/type').default

      injectReducer(store, { key: 'type', reducer })

      cb(null, Type)
    }, 'type')
  }
})

这里的
typedetailscocontainer
return与
表格
完全不同。我尝试了一个简单的
h1
,但仍然有错误

您可以使用
链接
组件来完成此操作:

import { Link } from 'react-router'

...

<Link to={`/dashboard/types/${this.props.types[index].id}`}>Dashboard page</Link>
从'react router'导入{Link}
...
仪表板页面
我解决了它

createRoutes
方法中,我必须通过其异步版本
getChildRoutes
更改根
childRoutes

因此,
createRoutes
方法变为(
TypeRoute
重新组合
TypeListRoute
TypeDetailRoute


我正在使用
react工具箱
组件,因此我不知道是否可以通过
链接
更改所有行。有没有可以调用的等效方法?似乎
链接
组件也在使用
推送
方法()@Thomashiebaud您能用
中呈现的组件更新问题吗。如果URL正在更改,但页面在视觉上没有更新,那么React可能会说“没有更改,不需要重新呈现”。因此,我认为这与路由无关(您的方法应该可以正常工作)。我在问题中添加了更多详细信息。我发现您是异步加载还原程序,可能使用了
store.replaceReducer
。这样行吗?我的意思是,我曾经看到过类似的行为;路由更改,但新页面无法呈现,因为替换reducer出错并在我的控制台中引发了一些错误。:)它似乎工作得很好。它正在与其他路由一起工作,我在控制台中没有一个错误您有整个项目的github链接吗?恐怕没有,这是一个公司项目,我无权共享它
export const TypeDetailsRoute = store => ({
  path: ':id',
  getComponent (nextState, cb) {
    require.ensure([], (require) => {
      const Type = require('./containers/TypeDetailsContainer').default

      const reducer = require('./modules/type').default

      injectReducer(store, { key: 'type', reducer })

      cb(null, Type)
    }, 'type')
  }
})
import { Link } from 'react-router'

...

<Link to={`/dashboard/types/${this.props.types[index].id}`}>Dashboard page</Link>
export const createRoutes = store => ({
  getChildRoutes (nextState, cb) {
    cb(null, [{
      path: '/',
      component: HomeLayout,
      indexRoute: Home,
      childRoutes: [
        LoginRoute(store),
        LogoutRoute(store),
        SignupRoute(store)
      ]
    }, {
      path: '/dashboard',
      component: requireAuthentication(DashboardLayout),
      indexRoute: Dashboard,
      childRoutes: [
        DeviceRoute(store),
        UserRoute(store),
        TypeRoute(store)
      ]
    }])
  }
})