@sonnetjs/router
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

sonnetjs/router

A simple and lightweight router for SonnetJS.

Installation

npm i @sonnetjs/router

Usage

// src/router.ts
import {
  RouteObject,
  createBrowserHistory,
  createRouter,
} from '@sonnetjs/router';

import Home from './pages/Home';
import About from './pages/About';
import Contact from './pages/Contact';

import RootComponent from './partials/Layout';

const routes: RouteObject[] = [
  {
    rootComponent: RootComponent,
    children: [
      { path: '/', component: Home },
      { path: '/about', component: About },
      { path: '/contact', component: Contact },
    ],
  },
];

const history = createBrowserHistory();

export const router = createRouter({
  routes,
  history,
});
// src/main.ts
import App from './App';
import { router } from './router';

import { createApp } from '@sonnetjs/core';

const app = createApp();
app.root(App);
app.use(router);
app.lazy();
app.mount('#app');
app.initialized();

Package Sidebar

Install

npm i @sonnetjs/router

Weekly Downloads

9

Version

0.0.4

License

MIT

Unpacked Size

18.4 kB

Total Files

4

Last publish

Collaborators

  • htmujahid