【问题标题】:Remove queryKey from hashHistory react-router-redux从 hashHistory react-router-redux 中删除 queryKey
【发布时间】:2016-11-04 04:49:12
【问题描述】:

我发现几个地方说要设置queryKey: false,但我找不到使用我正在使用的特定包设置它的位置。这是我当前的设置:

import { hashHistory } from 'react-router'
import { syncHistoryWithStore } from 'react-router-redux'
import createStore from './store/createStore'

const store = createStore(initialState, hashHistory)
const history = syncHistoryWithStore(hashHistory, store, {
  selectLocationState: (state) => state.router
})

【问题讨论】:

    标签: reactjs redux react-router react-redux react-router-redux


    【解决方案1】:

    示例 { queryKey: false }

    import React from 'react'
    import ReactDOM from 'react-dom'
    import { createStore, combineReducers, applyMiddleware } from 'redux'
    import { Provider } from 'react-redux'
    import reducers from '<project-path>/reducers'
    
    import { createHashHistory } from 'history'
    import { Router, Route, useRouterHistory } from 'react-router'
    
    import { syncHistoryWithStore, routerReducer,routerMiddleware, push } from 'react-router-redux'
    
    
    // Apply the middleware to the store
    const reduxRouterMiddleware = routerMiddleware(browserHistory)
    
    const store = createStore(
        combineReducers({
          ...reducers,
          routing: routerReducer
      }),
      initialState,
      applyMiddleware(reduxRouterMiddleware)
    )
    //set { queryKey: false }
    const appHashHistory = useRouterHistory(createHashHistory)({ queryKey: false })
    
    // Create an enhanced history that syncs navigation events with the store
    const history = syncHistoryWithStore(appHashHistory, store)
    
    ReactDOM.render(
      <Provider store={store}>
        { /* Tell the Router to use our enhanced history */ }
        <Router history={history}>
          <Route path="/" component={App}>
            <Route path="foo" component={Foo}/>
            <Route path="bar" component={Bar}/>
          </Route>
        </Router>
      </Provider>,
      document.getElementById('mount')
    )
    

    【讨论】:

      猜你喜欢
      • 2018-02-11
      • 2015-11-28
      • 2016-04-08
      • 2018-09-16
      • 2017-09-01
      • 2016-09-18
      • 1970-01-01
      • 2018-02-09
      • 2017-06-14
      相关资源
      最近更新 更多