All Projects → hamedasemi → Lit Element Router

hamedasemi / Lit Element Router

A LitElement Router (1278 bytes gzip)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Lit Element Router

Regexparam
A tiny (308B) utility that converts route patterns into RegExp. Limited alternative to `path-to-regexp` 🙇‍♂️
Stars: ✭ 390 (+358.82%)
Mutual labels:  router, regex
Storeon Async Router
Asynchronous router for Storeon. It provides possibility for prefetch the data, lazy load, navigation cancellation, and routes modification on the fly.
Stars: ✭ 22 (-74.12%)
Mutual labels:  router, routing
Router
🛣 Simple Navigation for iOS
Stars: ✭ 438 (+415.29%)
Mutual labels:  router, routing
Cortex
Routing system for WordPress
Stars: ✭ 300 (+252.94%)
Mutual labels:  router, routing
Url Mapper
Take a URL and map to functions, parsing params
Stars: ✭ 39 (-54.12%)
Mutual labels:  router, routing
Freerouting
Advanced PCB autorouter (finally, no Java installation required)
Stars: ✭ 307 (+261.18%)
Mutual labels:  router, routing
Koa Dec Router
An ES6 decorator + class based router, support inherit, override, priority, auto load controllers, etc.
Stars: ✭ 19 (-77.65%)
Mutual labels:  decorators, router
Ffrouter
Powerful and easy-to-use URL routing library in iOS that supports URL Rewrite(强大、易用、支持 URL Rewrite的 iOS 路由库)
Stars: ✭ 263 (+209.41%)
Mutual labels:  router, routing
React Router Component
Declarative router component for React.
Stars: ✭ 879 (+934.12%)
Mutual labels:  router, routing
Routing
The Routing component maps an HTTP request to a set of configuration variables.
Stars: ✭ 7,080 (+8229.41%)
Mutual labels:  router, routing
Fluro
Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.
Stars: ✭ 3,372 (+3867.06%)
Mutual labels:  router, routing
Corenavigation
📱📲 Navigate between view controllers with ease. 💫 🔜 More stable version (written in Swift 5) coming soon.
Stars: ✭ 69 (-18.82%)
Mutual labels:  router, routing
Abstract State Router
Like ui-router, but without all the Angular. The best way to structure a single-page webapp.
Stars: ✭ 288 (+238.82%)
Mutual labels:  router, routing
Graphpath
Graphpath generates an ASCII network diagram from the route table of a Unix/Linux
Stars: ✭ 321 (+277.65%)
Mutual labels:  router, routing
Simple Php Router
Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
Stars: ✭ 279 (+228.24%)
Mutual labels:  router, routing
Micro Router
🚉 A tiny and functional router for Zeit's Micro
Stars: ✭ 621 (+630.59%)
Mutual labels:  router, routing
gatsby-plugin-dynamic-routes
Creating dynamic routes based on your environment and/or renaming existing routes
Stars: ✭ 14 (-83.53%)
Mutual labels:  router, routing
giuseppe
A controller routing system for expressJS with TypeScript decorators and annotations
Stars: ✭ 49 (-42.35%)
Mutual labels:  decorators, routing
Bidi
Bidirectional URI routing
Stars: ✭ 941 (+1007.06%)
Mutual labels:  router, routing
Restify Router
A router interface for restify that lets you aggregate route definitions and apply to a restify server
Stars: ✭ 45 (-47.06%)
Mutual labels:  router, routing

LitElement Router

A LitElement Router (1278 bytes gzip) that uses JavaScript Mixin, Decorators and RegExp.

Coverage Status npm version Published on webcomponents.org Known Vulnerabilities CircleCI

Installation

npm install lit-element-router --save

Working Examples

You can find working example projects on StackBlitz:

Simple: https://stackblitz.com/edit/lit-element-router
Authentication: https://stackblitz.com/edit/lit-element-router-authentication
Authentication and Authorization (todo): https://stackblitz.com/edit/lit-element-router-authentication-and-authorization
Advanced (todo): https://stackblitz.com/edit/lit-element-router-advanced
Multi Router (todo): https://stackblitz.com/edit/lit-element-router-multi
All In One: https://stackblitz.com/edit/lit-element-router-all-in-one

Usage

Add the Router to LitElement using the router method then register the routes and the router callback.

import { LitElement, html } from 'lit-element';
import { router } from 'lit-element-router';

import './app-link';
import './app-main';

@router
class App extends LitElement {
// OR
class App extends router(LitElement) {
  static get properties() {
    return {
      route: { type: String },
      params: { type: Object },
      query: { type: Object }
    };
  }

  static get routes() {
    return [{
      name: 'home',
      pattern: '',
      data: { title: 'Home' }
    }, {
      name: 'info',
      pattern: 'info'
    }, {
      name: 'user',
      pattern: 'user/:id'
    }, {
      name: 'not-found',
      pattern: '*'
    }];
  }

  constructor() {
    super();
    this.route = '';
    this.params = {};
    this.query = {};
  }

  router(route, params, query, data) {
    this.route = route;
    this.params = params;
    this.query = query;
    console.log(route, params, query, data);
  }

  render() {
    return html`
      <app-link href="/">Home</app-link>
      <app-link href="/info">Info</app-link>
      <app-link href="/info?data=12345">Info?data=12345</app-link>
      <app-link href="/user/14">user/14</app-link>

      <app-main active-route=${this.route}>
          <h1 route='home'>Home</h1>
          <h1 route='info'>Info ${this.query.data}</h1>
          <h1 route='user'>User ${this.params.id} </h1>
          <h1 route='not-found'>Not Found </h1>
      </app-main>
    `;
  }
}

customElements.define('my-app', App);

Add the Outlet to LitElement using the outlet method.

import { LitElement, html } from 'lit-element';
import { outlet } from 'lit-element-router';

@outlet
class Main extends LitElement {
// OR
class Main extends outlet(LitElement) {
  render() {
    return html`
      <slot></slot>
    `;
  }
}

customElements.define('app-main', Main);

Add the Navigator to LitElement using the navigator method then use the navigate method to navigate.

import { LitElement, html } from 'lit-element';
import { navigator } from 'lit-element-router';

@navigator
class Link extends LitElement {
// OR
class Link extends navigator(LitElement) {
    static get properties() {
        return {
            href: { type: String }
        };
    }
    constructor() {
        super();
        this.href = '';
    }
    render() {
        return html`
            <a href='${this.href}' @click='${this.linkClick}'>
                <slot></slot>
            </a>
        `;
    }
    linkClick(event) {
        event.preventDefault();
        this.navigate(this.href);
    }
}

customElements.define('app-link', Link);

Supported Browsers

Edge
Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
iOS Safari
Mobile Safari
Samsung
Samsung
Opera
Opera
Electron
Electron
Last 2 versions Last 2 versions Last 2 versions Last 2 versions Last 2 versions Last 2 versions Last 2 versions Last 2 versions

Contributors

Hamed Asemi
Hamed Asemi
Lazy Llama
Lazy Llama
Andreas Kohn
Andreas Kohn
zzzgit
zzzgit
truongminh
Nguyễn Trường Minh

Contributions

Clone these two repositories and put them side by side in a common folder:

git clone [email protected]:hamedasemi/lit-element-router.git
git clone [email protected]:hamedasemi/lit-element-router-test.git

Navigate to both lit-element-router and lit-element-router-test directories and install dependencies

npm install

Navigate to lit-element-router-test and run the webpack dev server

npm run serve

Start the development on lit-element-router, observe and test changes right in the lit-element-router-test live

Run the test locally (only necessary if you are developing the utility)

npm test

Add your name and picture to the contributors' list at lit-element-router repository https://github.com/hamedasemi/lit-element-router#contributors

Create a pull request of your changes on both repositories lit-element-router and lit-element-router-test

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].