博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
react-router-dom 之 Link 与NavLink
阅读量:4112 次
发布时间:2019-05-25

本文共 1006 字,大约阅读时间需要 3 分钟。

本文主要记录react项目react-router的使用,主要介绍两种,Link 和 NavLink

//menuList.js 导航条import { NavLink ,Link} from 'react-router-dom'
{childItem.title}
//routeConfig.jsimport { Route } from 'react-router-dom'

1、Link

当 你点击<Link>时,url会更新,组件会被重新渲染,但是页面不会重新加载,to可以是字符串也可以是对象,to={

{pathname: '/courses',search: '?sort=name',hash: '#the-hash',state: { fromDashboard: true }}

// to为string
关于 // to为obj
// replace

2、NaviLink

NavLink

<NavLink>是<Link>的一个特定版本,会在匹配上当前的url的时候给已经渲染的元素添加参数,组件的属性有

activeClassName(string):设置选中样式,默认值为active

activeStyle(object):当元素被选中时,为此元素添加样式
exact(bool):为true时,只有当导致和完全匹配class和style才会应用
strict(bool):为true时,在确定为位置是否与当前URL匹配时,将考虑位置pathname后的斜线
isActive(func)判断链接是否激活的额外逻辑的功能
嗯、看例子就懂了

// activeClassName选中时样式为selected
FAQs
// 选中时样式为activeStyle的样式设置
FAQs
// 当event id为奇数的时候,激活链接const oddEvent = (match, location) => { if (!match) { return false } const eventID = parseInt(match.params.eventID) return !isNaN(eventID) && eventID % 2 === 1}
Event 123

 

转载地址:http://oemsi.baihongyu.com/

你可能感兴趣的文章
内联函数
查看>>
虚函数 析构函数
查看>>
树、二叉树、森林之间的转化
查看>>
堆排序
查看>>
二叉排序树 平衡二叉树
查看>>
创建索引
查看>>
new与delete
查看>>
线索二叉树
查看>>
外部排序 归并排序
查看>>
POJ 3255 Roadblocks 最短路Dijkstra+堆优化
查看>>
poj 3723 最大生成树
查看>>
poj 2139 Six Degrees of Cowvin Bacon 最短路bellman 多源最短路径 (一次AC)
查看>>
Codeforces Round #329 (Div. 2) A. 2Char 字符串+暴力
查看>>
poj 3259 Wormholes 最短路bellman 题意转化很重要
查看>>
poj 2456 Aggressive cows 整数二分写法 模板题
查看>>
poj 3104 Drying 二分搜索--查找最小yes值
查看>>
poj 3111 K Best 二分搜索 最大化平均值
查看>>
POj 3258 River Hopscotch 二分搜索 最大化最小值
查看>>
poj 2674 Linear world 弹性碰撞 升级的蚂蚁
查看>>
poj 2785 4 Values whose Sum is 0
查看>>