@stembord/location
TypeScript icon, indicating that this package has built-in type declarations

0.1.12 • Public • Published

ts-location

url location handling for browsers

import url = require("url");
import { createLocation } from "@stembord/location";

const { parse } = url;

const handler = (url: url.UrlWithParsedQuery) =>
    url.pathname === "/not_allowed"
        ? // redirect to home, rejecting with null will ignore the request
          Promise.reject(parse("/", true))
        : Promise.resolve(url);

const location = createLocation(window, { html5Mode: true, handler });

// succuss
location.set("/allowed").then(() => {
    console.log("succuss");
});

// failure
location.set("/not_allowed").catch(error => {
    console.error(error);
});

// remove DOM listeners
location.remove();

Readme

Keywords

Package Sidebar

Install

npm i @stembord/location

Weekly Downloads

10

Version

0.1.12

License

(MIT OR Apache-2.0)

Unpacked Size

41.3 kB

Total Files

16

Last publish

Collaborators

  • jwaterfaucett
  • nathanfaucett