lbweb-react
TypeScript icon, indicating that this package has built-in type declarations

2.1.11 • Public • Published

lbweb-react

NPM JavaScript Style Guide

安装

npm install --save lbweb-react
npm install --save react-router-dom history

使用

routes.tsx

import { RouteItem, useRoutes } from 'lbweb-react'
 
const routes: Array<RouteItem> = [
  {
    path: '/',
    name: '根路径',
    redirect: '/home',
  },
  {
    path: '*',
    name: 'BaseLayout',
    element: <BaseLayout></BaseLayout>,
    children: [
      {
        path: '/home',
        name: '首页',
        element: <div>首页</div>,
        before: async () => {
          console.log('进入首页')
        },
      },
    ],
  },
  {
    path: '/login',
    name: '登录',
    element: <div>登录</div>,
  },
  {
    path: '*',
    name: '404',
    element: <div>页面不存在</div>,
  },
]
 
export const Routes = () => {
  return useRoutes(routes)
}

index.tsx

import React, { Component } from 'react'
import { ConfigRouter } from 'lbweb-react'
import { Routes } from './routes'
 
function App() {
  return (
    <HashRouter>
      <ConfigRouter>
        <Routes></Routes>
      </ConfigRouter>
    </HashRouter>
  )
}
 
ReactDOM.render(<App />, document.getElementById('root'))

License

MIT © lblblong

Readme

Keywords

none

Package Sidebar

Install

npm i lbweb-react

Weekly Downloads

1

Version

2.1.11

License

MIT

Unpacked Size

98.6 kB

Total Files

20

Last publish

Collaborators

  • lblblong