Skip to content

Commit

Permalink
feat: template
Browse files Browse the repository at this point in the history
  • Loading branch information
htmujahid committed Oct 1, 2024
1 parent 9dced8f commit c97877f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 64 deletions.
4 changes: 2 additions & 2 deletions packages/create-sonnet/template/code/router/src/main.js
Original file line number Diff line number Diff line change
@@ -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();
32 changes: 0 additions & 32 deletions packages/create-sonnet/template/code/router/src/router.js

This file was deleted.

27 changes: 27 additions & 0 deletions packages/create-sonnet/template/code/router/src/routes.js
Original file line number Diff line number Diff line change
@@ -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();
56 changes: 27 additions & 29 deletions packages/sonnet-router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/sonnet-router/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sonnetjs/router",
"version": "0.0.5",
"version": "0.0.6",
"files": [
"dist"
],
Expand Down

0 comments on commit c97877f

Please sign in to comment.