@wgoo/cli
Version:
Wgoo Cli 是一个 React 组件库构建工具,通过 Wgoo Cli 可以快速搭建一套功能完备的 React 组件库。
43 lines (35 loc) • 939 B
JSX
import React from 'react';
import './style.less';
class RouterLink extends React.Component {
get path() {
const { item, base } = this.props;
return `${base}${item.path}`;
}
get active() {
if (window.location.hash.replace(/#\//g, '/') === this.path) {
return true;
}
return false;
}
replacePath = () => {
window.location.hash = '#' + this.path;
};
render() {
const { item } = this.props;
const name = item.title.split(' ');
const itemName = {
__html: `${name[0]} <span>${name.slice(1).join(' ')}</span>`,
};
if (item.path) {
return (
<a className={this.active ? 'active' : ''} onClick={this.replacePath} dangerouslySetInnerHTML={itemName}></a>
);
}
return item.link ? (
<a href={item.link} dangerouslySetInnerHTML={itemName}></a>
) : (
<a dangerouslySetInnerHTML={itemName}></a>
);
}
}
export default RouterLink;