1.1.4 • Published 11 months ago
@beforesemicolon/router v1.1.4
Web Component based Router
Web component router based on Markup.
Motivation
- a router that works for MPA, SPA, and hybrid Apps are rare
- web standards alone routing is hard to work with
- it takes time to implement a custom router
- most routers out there are framework specific
- routers out there require JavaScript code to be written and a powerful component tag simplifies that
- available routers dont handle both JavaScript, text, and HTML files loading
- web components work with everything which makes it a perfect candidate for a router
<!-- index.html -->
<nav>
<!-- navigate with ability to update title and pass data via payload attribute -->
<page-link path="/" title="Welcome" payload='{"heading": "Home content"}'
>Home</page-link
>
<page-link path="/todos" search="tab=one" title="Manage todos"
>Todos</page-link
>
<page-link path="/contact" title="Contact">Contact</page-link>
</nav>
<!-- wrap the content to render based on url pathname -->
<page-route path="/">
<h1>
<!-- render page metadata like specified payload,
path and search query param values -->
<page-data key="heading"> Home content </page-data>
</h1>
<p>This is home content</p>
<div class="tabs">
<div class="tab-header">
<!-- update search query -->
<page-link search="tab=one">Tab 1</page-link>
<page-link search="tab=two">Tab 2</page-link>
</div>
<div class="tab-content">
<!-- render content base on specific search query values -->
<page-route-query key="tab" value="one">
Tab One content
</page-route-query>
<page-route-query key="tab" value="two">
Tab Two content
</page-route-query>
</div>
</div>
<!-- choose to ALWAYS redirect to a default location when no url match -->
<page-redirect type="always" path="/?tab=one"></page-redirect>
</page-route>
<!-- nest routes to create complex sitemap
by allowing path to not be matched exactly (default) -->
<page-route path="/todos" exact="false">
<!-- child routes are aware of their parent routes
no matter where they are rendered
and will always extend their parent paths -->
<page-route src="./pages/todos.js"></page-route>
<!-- use pathname params to specify variables in the pathname -->
<page-route path="/:todoId" src="./pages/todo-item.js"></page-route>
</page-route>
<!-- load content from text, HTML, or JavaScript files -->
<page-route path="/contact" src="./pages/contact.js"></page-route>
<page-route path="/404"> 404 - Page not found! </page-route>
<!-- force redirect when pathnames are unknown -->
<page-redirect path="/404" title="404 - Page not found!"></page-redirect>Examples
Installation
npm install @beforesemicolon/routervia CDN:
<!-- required WebComponent Markup to be present -->
<script src="https://unpkg.com/@beforesemicolon/web-component/dist/client.js"></script>
<!-- use the latest version -->
<script src="https://unpkg.com/@beforesemicolon/router/dist/client.js"></script>
<!-- use a specific version -->
<script src="https://unpkg.com/@beforesemicolon/router@0.1.0/dist/client.js"></script>
<!-- link you app script after -->
<script>
const { ... } = BFS.ROUTER
</script>1.1.1
12 months ago
1.1.0
12 months ago
1.0.0
12 months ago
0.19.0-next
1 year ago
0.20.0-next
1 year ago
0.18.0-next
1 year ago
1.1.4
11 months ago
1.1.3
11 months ago
1.1.2
11 months ago
0.19.1-next
1 year ago
0.18.1-next
1 year ago
1.0.0-next
12 months ago
0.21.0-next
12 months ago
0.17.2-next
1 year ago
0.17.0-next
1 year ago
0.17.1-next
1 year ago
0.12.0-beta
1 year ago
0.11.0-beta
1 year ago
0.17.0-beta
1 year ago
0.10.0-beta
1 year ago
0.16.0-beta
1 year ago
0.15.0-beta
1 year ago
0.14.0-beta
1 year ago
0.13.0-beta
1 year ago
0.9.0-beta
1 year ago
0.8.0-beta
1 year ago
0.7.0
1 year ago
0.6.0
2 years ago
0.3.0
2 years ago
0.5.0
2 years ago
0.4.0
2 years ago
0.2.0
2 years ago
0.1.0
2 years ago