use-router-hook
v2.0.5
Published
a react hook that provide a sample frontend router system
Downloads
12
Readme
useRouter
使用方式
function RouterComponent(){
const [history, OutLet] = useRouter({
routes: [
{
pathname: '/home',
component: Home
},
{
pathname: '/about',
component: About
}
]
callbacks: [...callbacks],
initialPath: '/home',
});
return <>
<menu>
<button onClick={()=>history.back()}><</button>
<button onClick={()=>history.push('/home')}>Home</button>
<button onClick={()=>history.push('/about')}>About</button>
<button onClick={()=>history.forward()}>></button>
</menu>
<OutLet/>
</>
}