0.0.1 • Published 2 years ago
@dovm/router v0.0.1
DOVM Router
This is the official router for DOVM.
Usage
Declare a route table:
// routes.ts
import { Navigation, Route, RouteParams } from '@dovm/router';
export class IndexNavigation extends Navigation {
static resolve(params: RouteParams): IndexNavigation | undefined {
return new IndexNavigation();
}
}
export const Routes: Route[] = [
new Route(IndexNavigation, {
path: '/',
view: async c => {
const { default: component } = await import(/* webpackChunkName: "home" */ './home');
return new component({
services: c.services,
container: c.container,
attrs: {},
slots: {}
});
}
})
];
Register a router to IoC container:
import { ServiceCollection } from '@dovm/core';
import { Router } from '@dovm/router';
import { Routes } from './routes';
const services = new ServiceCollection();
services.add(Router, () => new Router(Routes));
Render view:
<component class="RouterView" src="@dovm/router"></component>
<template>
<router-view>
<template #main>The page you are requested does not exists.</template>
<template #loading>Loading...</template>
</router-view>
</template>
License
MIT
0.0.1
2 years ago