Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

knockout-router

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knockout-router

Simple router designed for usage with Knockout JS components

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
37
increased by146.67%
Maintainers
1
Weekly downloads
 
Created
Source

Knockout Router

Simple router designed for usage with Knockout JS components with syntax inspired by ReactRouter

Build Status GitHub license npm version

Example

<knockout-router rootUrl="/virtualApp" params="actions: actions">
  <home-view route="/:userId" action="loadUser"></home-view>
  <feeds-view route="/:userId/feeds" action="loadFeeds"></feeds-view>
</knockout-router>

<template id="home-view">
  <h1>Home</h1>
  <a data-bind="path: '~/' + params.userId() + '/feeds'">Feeds</a>
</template>

<template id="feeds-view">
  <h1>Feeds</h1>
  <a data-bind="path: '~/' + params.userId() + '/feeds'">Posts</a>
  <a data-bind="path: '~/' + params.userId() + '/feeds/images'">Images</a>
  
  <knockout-router routePrefix="/:userId/feeds">
    <posts-view route="/"></posts-view>
    <images-view route="/images"></images-view>
  </knockout-router>
</template>

<template id="posts-view">
  <h2>Posts</h2>
</template>

<template id="images-view">
  <h2>Images</h2>
</template>
import ko from "knockout";
import "knockout-router";

Array.from(document.querySelectorAll("template"))
  .map(node => node.getAttribute("id"))
  .forEach(id => {
    ko.components.register(id, template: { element: id });
  });

ko.applyBindings({
  actions: {
    async loadUser({ params }) {
      let resp = await fetch("/api/users/" + params.userId);
      // ...
    },
    async loadFeeds({ params }) {
      let resp = await fetch("/api/feets/" + params.userId);
      // ...
    }
  }
});

Documentation

Configuring routes

TBD

Router options

Route options

Actions and route context

TBD

Actions

Route context

Route component lifecycle

Custom bindings

TBD

path

query

activePathCss

Keywords

FAQs

Package last updated on 12 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc