0
私はreact-router 4.xと互換性がある次の(5.0.0-alpha.6)バージョンのreact-router-reduxを使用しています。 次のページにリダイレクトしている間に、URLにパラメータを設定しようとしています。React-Router-ReduxがLOCATION_CHANGEを2回送出し、検索値を削除します。
次のページに移動するたびに。私はそれが@LOCATION_CHANGE 2時間、in the second time it removes search valueを呼ぶことを理解します。私はボタンイベントから
import { requireAuth } from '../components/AuthenticatedComponent'
import createHistory from 'history/createBrowserHistory'
const history = createHistory()
return (
<ConnectedRouter history={history}>
<div className="container">
<Header />
<Switch>
<Route exact path="/" component={Home} />
<Route path="/about" component={requireAuth(About)} />
<Route path="/login" component={Login} />
<Route component={NotFound} />
</Switch>
</div>
</ConnectedRouter>
)
AuthenticatedComponent.js私はあなたがnextPropsでパス名を渡すべきだと思い
import { push } from 'react-router-redux'
export function requireAuth(Component) {
class AuthenticatedComponent extends React.Component {
componentWillMount() {
this.checkAuth(this.props.isAuthenticated);
}
componentWillReceiveProps(nextProps) {
this.checkAuth(nextProps.isAuthenticated);
}
checkAuth(isAuthenticated) {
if (!isAuthenticated) {
let redirectAfterLogin = this.props.location.pathname;
this.props.dispatch(push({pathname: "/login", search:`?redirect=${redirectAfterLogin}`}))
}
}
//....
}
おかげで私にとって https://gyazo.com/77ca970422d4e29d6dcc418435417977を動作しないように思えます –