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

0.2.3 • Public • Published

ts-location

url location handling for browsers

import url = require("url");
import { createLocation } from "@aicacia/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 @aicacia/location

Weekly Downloads

7

Version

0.2.3

License

(MIT OR Apache-2.0)

Unpacked Size

50.9 kB

Total Files

45

Last publish

Collaborators

  • nathanfaucett