0.0.1 • Published 2 years ago

taomu-routes v0.0.1

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

taomu-routes

base: react-router-dom

Install

npm install taomu-routes

Import Global Types

in tsconfig.json

{
  "compilerOptions": {
    "types": ["taomu-routes/types"]
  }
}

Create routes

in src/main.ts

import React from 'react'
import { createRoot } from 'react-dom/client'

import { AutoRoutes, AppRouter } from 'taomu-routes'

// with vite
const routes = new AutoRoutes(import.meta.glob('./views/**/routes.(ts|tsx)', { eager: true }))

const root = createRoot(document.getElementById('root')!)

root.render(
  <div>
    <React.StrictMode>
      <AppRouter routes={routes} />
    </React.StrictMode>
  </div>
)

Route Config

in src/views/**/routes.ts

export const autoRoutes: RouteConfig[] = [
  {
    name: 'home',
    path: '/home',
    title: 'Home',
    element: () => import('./home'),
  },
]

Navigation

You can use 'navigateTo' to navigate to any route from anywhere.

import { routeTools } from 'taomu-routes'

routeTools.navigateToByRouteName('home')

// or

routeTools.navigateTo('/home')

Link

You can use 'Link' to navigate to any route in AppRouter context.

import { Link } from 'taomu-routes'

const Comp = () => {
  return (
    <div>
      <Link name="home">To Home</Link>
      {/* or */}
      <Link to="/home">To Home</Link>
    </div>
  )
}

LICENSE

Apache-2.0

0.1.0

2 years ago

0.0.3

2 years ago

0.1.1

2 years ago

0.0.2

2 years ago

0.0.5

2 years ago

0.1.3

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.1

2 years ago