【问题标题】:react-toolbox Link refreshing entire pagereact-toolbox 链接刷新整个页面
【发布时间】:2017-04-25 12:48:43
【问题描述】:

我在我的一个项目中使用react-toolbox。

应用结构

App
--Navigation
--Content
App

应用组件

<div>
  <HomeNav />
  {this.props.children}
</div>

HomeNav 组件

import { Link } from 'react-router';
...
<Navigation type="horizontal">
  <Link to="animals">Animals</Link>
  <Link to="plants">Plants</Link>
</Navigation>

注意:Link 导入自 react-router

路线

<Route path="/" component={App}>
  <IndexRedirect to="/animals" />
  <Route path="animals" component={AnimalsPage} />
  <Route path="plants" component={PlantsPage} />
</Route>

按预期工作正常;在路由之间切换时仅刷新Content。但是当我使用react-toolbox中的Link组件时,整个页面正在刷新。

import { Link } from 'react-toolbox/lib/link';
...
<Navigation type="horizontal">
  <Link
    active
    href="animals"
    label="Animals"
  />
  <Link
    href="plants"
    label="Plants"
  />
</Navigation>

有没有办法改变这种行为?

在react-toolbox 文档中,# 用于路由(#/components/link)。但是我在路由中使用# 有限制。

【问题讨论】:

  • 一个链接负责导航。如果您不能使用哈希路由,则需要拦截链接点击并执行event.stopPropagation() 或使用 Link 以外的其他方式。

标签: reactjs react-toolbox


【解决方案1】:

我搞定了:

import AppBar from 'react-toolbox/lib/app_bar';
import {Link} from 'react-router-dom';

<AppBar title={viewModelProps.headerTitle} leftIcon="menu">
  <Link to="/">Home</Link>
  <Link to="/login">Login </Link>
</AppBar>

【讨论】:

    猜你喜欢
    • 2017-05-19
    • 2020-12-31
    • 2017-01-01
    • 2019-11-11
    • 2016-01-27
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    相关资源
    最近更新 更多