0.4.0 • Published 3 years ago

srh-react-route-hook v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

React-Route-Hook

使用 react-hook 集成 route5

和官方的方案比更加灵活和更小的侵入性

快速开始

yarn add srh-react-route-hook

import { initRouter } from './react-route-hook';

export const useRoute = initRouter(
  [
    { name: 'home', path: '/home' },
    { name: 'login', path: '/login' },
  ],
  {
    defaultRoute: 'home',
    startPath: '/home',
  },
);

function HomePage(){
  const [routeActive] = useRoute('home') // 和 routes 中的匹配
  if(routeActive){
    return (
      <div> In Home Page</div>
    )
  } else {
    return null
  }
}

通过状态来响应路由, 控制页面的渲染过程, 就这么简单 O(∩_∩)O哈哈~