Custom Link
程序员文章站
2022-06-09 16:00:57
...
Custom Link
/**
* Created by mapbar_front on 2019/7/19.
*/
import React,{Component} from 'react';
import {
BrowserRouter as Router,
Route,
Link,
} from 'react-router-dom';
import Home from './../Home/Home';
import About from './../About/About';
function OldSchoolMenuLink({label,to,activeOnlyWhenExact}){
return(
<Route
path={to}
exact = {activeOnlyWhenExact}
children = {({match})=>(
<div className={match?"active":""}>
{match?">":""}
<Link to={to}>{label}</Link>
</div>
)}
/>
)
}
class CustomLink extends Component{
render(){
return(
<Router>
<ul>
<OldSchoolMenuLink activeOnlyWhenExact={true} to="/" label="Home"/>
<OldSchoolMenuLink to="/about" label="About"/>
</ul>
<hr/>
<Route exact path="/" component={Home}/>
<Route path="/about" component={About}/>
</Router>
)
}
}
export default CustomLink;
这个例子主要体现了Route组件中children的基本用法。
推荐阅读
-
HTML5资源预加载(Link prefetch)详细介绍(给你的网页加速)
-
解决ie动态修改link样式,import css不刷新的问题
-
D-link 500 路由设置方法与应用技巧
-
WI-Fi5最后疯狂 2019年路由器报告:TP-Link跌落神坛
-
TP-Link发布TL-XDR6060易展Turbo版:Wi-Fi 6/5952Mbps 通吃任何户型
-
oracle impdp network_link参数使用介绍
-
TextView显示文本控件两种方法 TextView显示link的方法
-
php生成的html meta和link标记在body标签里 顶部有个空行
-
link和@import的区别
-
Dalsa 8K彩色相机Camera link C#采图