onClick浏览器重定向到不同的URL - Reactjs

时间:2017-02-24 10:52:03

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

场景是我在一个页面上,例如http://example.com/order-confirmation以前的网址是/ payment。现在,当用户按下后退按钮时,我想将它们重定向到主页,即URL' /'但它会回到/付款页面。 我在我的申请中使用了react("^15.1.0")react-router("^2.4.1")以及react-router-redux("^4.0.4")

我试过在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>
);

有没有办法覆盖这种行为? 请建议...... 在此先感谢:)

2 个答案:

答案 0 :(得分:0)

你能试试这段代码吗?

DatabaseConfigProvider.get[JdbcProfile]

答案 1 :(得分:0)

尝试以下方法:

import { browserHistory } from 'react-router'

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) => {
    browserHistory.push('/');
};