0.6.0 • Published 4 years ago
@wces/router v0.6.0
\
This webcomponent follows the open-wc recommendation.
Installation
npm i @wces/router
Example Usage
<script type="module">
import { html, render } from "lit-html";
import './wces-router.js';
import './demo/app-page1.js';
const routes = [
{
id: 'page1',
pattern: '(/)',
component: 'app-page1'
},
{
id: 'page2',
pattern: '/page2/:name',
component: 'app-page2',
url: '/demo/app-page2.js',
context: async ({params: { name }}) => ({ greeting: `Hello ${name}`})
}
];
const route404 = {
id: 'route404',
component: 'app-404',
url: '/demo/app-404.js'
}
window.addEventListener('load', () => {
const rootEl = document.getElementById('demo');
render(
html`<wces-router .routes="${routes}" .route404="${route404}"></wces-router>`,
rootEl
);
})
</script>
<div id="demo"></div>
Features
Lazy loading
...
Route path params and query params
...
Optional 404 route
...
Linting with ESLint, Prettier, and Types
To scan the project for linting errors, run
npm run lint
You can lint with ESLint and Prettier individually as well
npm run lint:eslint
npm run lint:prettier
To automatically fix many linting errors, run
npm run format
You can format using ESLint and Prettier individually as well
npm run format:eslint
npm run format:prettier
Testing with Karma
To run the suite of karma tests, run
npm run test
To run the tests in watch mode (for TDD, for example), run
npm run test:watch
Tooling configs
For most of the tools, the configuration is in the package.json
to reduce the amount of files in your project.
If you customize the configuration a lot, you can consider moving them to individual files.
Local Demo with es-dev-server
npm start
To run a local development server that serves the basic demo located in index.html