diff --git a/packages/create-sonnet/template/code/router/src/main.js b/packages/create-sonnet/template/code/router/src/main.js index 7dd8ec5..c1eb9e7 100644 --- a/packages/create-sonnet/template/code/router/src/main.js +++ b/packages/create-sonnet/template/code/router/src/main.js @@ -1,12 +1,12 @@ import App from './App'; -import { router } from './router'; +import { routers } from './routes'; import './style.css'; import { createApp } from '@sonnetjs/core'; const app = createApp(); app.root(App); -app.use(router); +app.use(routers); app.lazy(); app.mount('#app'); app.initialized(); \ No newline at end of file diff --git a/packages/create-sonnet/template/code/router/src/router.js b/packages/create-sonnet/template/code/router/src/router.js deleted file mode 100644 index b270a90..0000000 --- a/packages/create-sonnet/template/code/router/src/router.js +++ /dev/null @@ -1,32 +0,0 @@ -import { - createBrowserHistory, - createRouter, -} from '@sonnetjs/router'; - -const routes = [ - { - rootComponent: async () => (await import('./partials/Layout')).default(), - children: [ - { - path: '/', - component: async () => (await import('./pages/Home')).default(), - }, - { - path: '/about', - component: async () => (await import('./pages/About')).default(), - }, - { - path: '/contact', - component: async () => (await import('./pages/Contact')).default(), - }, - ], - }, -]; - -const history = createBrowserHistory(); - -export const router = createRouter({ - routes, - history, - mountedId: '#app-1', -}); \ No newline at end of file diff --git a/packages/create-sonnet/template/code/router/src/routes.js b/packages/create-sonnet/template/code/router/src/routes.js new file mode 100644 index 0000000..8d67e95 --- /dev/null +++ b/packages/create-sonnet/template/code/router/src/routes.js @@ -0,0 +1,27 @@ +import { router, createBrowserHistory, createRouter } from '@sonnetjs/router'; + +export const routes = router() + .layout(async () => (await import('./partials/Layout')).default()) + .children([ + router() + .path('/') + .component(async () => (await import('./pages/Home')).default()) + .get(), + router() + .path('/about') + .component(async () => (await import('./pages/About')).default()) + .get(), + router() + .path('/contact') + .component(async () => (await import('./pages/Contact')).default()) + .get(), + ]) + .get(); + +const history = createBrowserHistory(); + +export const routers = createRouter() + .routes(routes) + .history(history) + .mountedId('#app-1') + .get(); diff --git a/packages/sonnet-router/README.md b/packages/sonnet-router/README.md index 41841c9..dc85adf 100644 --- a/packages/sonnet-router/README.md +++ b/packages/sonnet-router/README.md @@ -11,48 +11,46 @@ npm i @sonnetjs/router ## Usage ```typescript -// 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 }, - ], - }, -]; +// src/routes.ts +import { router, createBrowserHistory, createRouter } from '@sonnetjs/router'; + +export const routes = router() + .layout(async () => (await import('./partials/Layout')).default()) + .children([ + router() + .path('/') + .component(async () => (await import('./pages/Home')).default()) + .get(), + router() + .path('/about') + .component(async () => (await import('./pages/About')).default()) + .get(), + router() + .path('/contact') + .component(async () => (await import('./pages/Contact')).default()) + .get(), + ]) + .get(); const history = createBrowserHistory(); -export const router = createRouter({ - routes, - history, -}); +export const routers = createRouter() + .routes(routes) + .history(history) + .mountedId('#app-1') + .get(); ``` ```typescript // src/main.ts import App from './App'; -import { router } from './router'; +import { routers } from './routes'; import { createApp } from '@sonnetjs/core'; const app = createApp(); app.root(App); -app.use(router); +app.use(routers); app.lazy(); app.mount('#app'); app.initialized(); diff --git a/packages/sonnet-router/package.json b/packages/sonnet-router/package.json index ad59eda..8e631ec 100644 --- a/packages/sonnet-router/package.json +++ b/packages/sonnet-router/package.json @@ -1,6 +1,6 @@ { "name": "@sonnetjs/router", - "version": "0.0.5", + "version": "0.0.6", "files": [ "dist" ],