如何忽略React路由器中的链接?

时间:2016-08-18 18:33:35

标签: javascript reactjs react-router

我正在尝试将反应路由器应用到我的应用程序中,但我遇到了一个问题,我有一些"链接"显示"模态"对话但反应路由器将它们视为路线并将我送回我的家中"页

  <a href="#" onClick={() => this.props.Show(true) }><i className="fa fa-plus" aria-hidden="true">

路由器

ReactDOM.render(
    <Provider store={store}>
      <Router history={hashHistory}>
      <Route path="/" component={Layout}>
        <IndexRoute component={Home}></IndexRoute>
        <Route path="app" name="app" component={App}></Route>
      </Route>
    </Router>
    </Provider>,
    document.getElementById('root')
);

该链接位于&#34; App&#34;成分

修改

我现在有了这个

 return (
            <a href="#" id="add-new-storage-item-btn" className={addNewItemClasses} onClick={(event) => this.setAddStorageItemModal(event) }><i className="fa fa-plus" aria-hidden="true"> Add New Item</i></a>
        );

  setAddStorageItemModal(event)
   {
       this.props.setAddStorageItemModal(true);
       event.stopPropagation();

   }

我尝试将event.stopPropagation作为第一行但不起作用。

1 个答案:

答案 0 :(得分:1)

如果您想阻止锚标记导航,建议您添加

event.stopPropagation()

到您的onClick事件处理程序。