这种情况是我在一个页面上,例如http://example.com/order-confirmation和以前的网址是/付款。现在,当用户按下返回按钮时,我想将它们重定向到主页,即URL'/',但它将返回到/付款页面。 我在我的应用程序中使用react("^15.1.0")
和react-router("^2.4.1")
和react-router-redux("^4.0.4")
。重定向到不同的网址onClick浏览器返回 - Reactjs
我试过在StackOverflow或git上的多个答案,但都是徒劳的。 例如下面我尝试:
import { push } from 'react-router-redux';
<Route
path={`${AppPaths.ORDER_CONFIRMATION}/:orderId`} component={OrderConfirmationContainer} onLeave={(prevState) => routeBackHome(store, prevState)}
onEnter={routeEntryHandler(store, nonGuestUserValidator)}
/>
const routeBackHome = (store, prevState) => {
store.dispatch(push(`/`));
};
我的路线:
export const createRoutes = store => (
<Route path={AppPaths.BASE} component={CheckoutAppContainer} onEnter={CheckoutAppContainer.fetchUserState(store)}>
<IndexRedirect to={`${AppPaths.BASE}/${AppPaths.BAG}`} />
<Route component={CheckoutWizardContainer} onLeave={() => clearNotifications(store)}>
<Route
path={AppPaths.BAG} component={CartContainer} onLeave={() => clearNotifications(store)}
onEnter={() => updateStepNumber(store, 1)}
/>
<Route
path={AppPaths.PAYMENT} component={QuickCheckoutContainer} onLeave={() => clearNotifications(store)}
onEnter={checkoutEntryHandler(store, 3)}
/>
</Route>
<Route
path={`${AppPaths.ORDER_CONFIRMATION}/:orderId`} component={OrderConfirmationContainer}
onEnter={routeEntryHandler(store, nonGuestUserValidator)}
/>
</Route>
);
有什么办法可以覆盖这种行为? 请建议... 在此先感谢:)
你能张贴代码? – juancab
请参阅编辑的问题。 –
您是否使用中间件将您的BrowserHistory与您的商店同步到您的Redux商店? – juancab