代码之家  ›  专栏  ›  技术社区  ›  yotke

<NavLink/>不会触发@@router/LOCATION\u更改操作

  •  0
  • yotke  · 技术社区  · 6 年前

    <NavLink /> 组件。 当前,当单击时,它将导航到正确的页面,但没有触发任何操作 redux

    redux-logger ).

    import React from 'react';
    import { connect } from 'react-redux';
    import { NavLink } from 'react-router-dom';
    
    import NavMenu from './NavMenu';
    
    const Nav = () => {
    
      return (
        <aside>
          <NavMenu />
          <NavFooter>
            <NavLink to={`/terms-and-conditions`}> // Not firing redux-logger actions, but navigates to the correct page
              Terms and conditions
            </NavLink>
          </NavFooter>
        </aside>
      );
    };
    
    export default connect()(Nav);
    

    当第一次加载和按下浏览器的后退/前进按钮时,redux logger中有一个路由更改:

    action @@router/LOCATION_CHANGE // console.log
    

    我到处都找了,找不到我是否需要做一个自定义操作或使用连接的路由器。

    感谢您的帮助

    1 回复  |  直到 6 年前
        1
  •  4
  •   yotke    6 年前

    显然,我有 <Router /> <Switch /> 除了 <ConnectedRouter />

    如果您想将路由连接到redux存储并在redux logger中反映路由的变化,您只需要 < 像这样:

    <ConnectedRouter history={history}>
        <Nav />
        <Switch>
           <Route path="/" exact component={Home} />
           <Route path="/about-the-cause" exact component={About} />
           <Redirect to="/" />
        </Switch>
    </ConnectedRouter>