0.1.3 • Published 12 months ago

taomu-routes v0.1.3

Weekly downloads
-
License
-
Repository
-
Last release
12 months 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

12 months ago

0.0.3

1 year ago

0.1.1

12 months ago

0.0.2

1 year ago

0.0.5

12 months ago

0.1.3

12 months ago

0.0.4

12 months ago

0.0.7

12 months ago

0.0.6

12 months ago

0.0.1

1 year ago