我正在尝试获取从通过查询参数发送的 api 发送的身份验证代码:
http://example.com?code=AUTH_CODE
但是,当页面加载时,它会转发到 url,而我没有在 React-Redux 中使用 Redux-Persist 和 React-Router-Redux。我可以在“persist/REHYDRATE”之前找到先前状态的查询参数,但无法持久保留路由减速器。我相信 Redux-Persist 会保留路由并消除查询参数。这是我的记录器输出的样子:
我可以在箭头所在的“上一个状态”处看到查询参数,但它已经通过下面的“下一个状态”消失了
我试过使用黑名单和 redux-persist-transform-filter 将“路由”列入黑名单,但没有成功。
这就是我的 index.js 的样子:
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux'
import { createStore, applyMiddleware, compose } from 'redux'
import registerServiceWorker from './registerServiceWorker';
import rootReducer from './reducers'
import { Router, browserHistory } from 'react-router'
import { syncHistoryWithStore } from 'react-router-redux'
import routes_design from './routes'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
import { PersistGate } from 'redux-persist/lib/integration/react'
const config = {
key: 'root',
storage
}
const reducer = persistReducer(config, rootReducer)
function configureStore () {
let store = createStore(
reducer,
compose(...) // Middleware here removed for brevity
)
let persistor = persistStore(store)
return { persistor, store }
}
const { persistor, store } = configureStore()
const history = syncHistoryWithStore(browserHistory, store)
ReactDOM.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<Router history={history} routes={routes_design}/>
</PersistGate>
</Provider>,
document.getElementById('root')
)
registerServiceWorker()