@stembord/location

url location set/back/forward for browsers

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
Minified + gzip package size for @stembord/location in KB

Readme

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();

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.