求一个 React Router 路由守卫的现成轮子
source link: https://www.v2ex.com/t/791940
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
第一次写 React,官方的路由没有封装守卫
由于路由这块我还不是很熟悉,求一个现成的轮子.
第 1 条附言 · 3 小时 33 分钟前
shilianmlxg 12 小时 37 分钟前
ericgui 6 小时 48 分钟前
SmiteChow 3 小时 39 分钟前
这玩意自己写不就几行代码么?
```app.jsx
import styles from '../css/app.cssm' assert { type: "css" }
import SideBar from './side-bar.jsx';
import ZYTable from './zy-table.jsx';
import BatchOperateZY from './batch-operate-zy.jsx';
const tabs = {
table: '资源管理',
batch: '批量操作',
};
export default function App(props) {
let hash = location.hash;
const [tab, setTab] = React.useState(hash === '' ? 'table' : hash.substr(1));
React.useEffect(() => {
document.title = `ZYMS 画廊 - ${tabs[tab]}`
document.location.hash = `#${tab}`
}, [tab])
return <div className={styles.flex}>
<SideBar tabs={tabs} tabName={tab} showTab={(name) => setTab(name)}/>
<div className={`${styles['tab-container']}`}>
{tab === 'table' && <ZYTable/>}
{tab === 'batch' && <BatchOperateZY/>}
</div>
</div>
}
```
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK