A Typescript browser URL manager
Why not.
npm i erre-ele --save
Import the ErreEle singleton instance:
import rl from 'erre-ele';
Review and use to your implementations how the IErreEle interface looks
export interface IErreEle<S> {
getParamFromURL: (pn: string) => string | null;
getPathnameFromURL: () => string | null;
go: (p: string, t?: string, s?: S) => void;
subscribeOnPopState: (onPopState?: (e: PopStateEvent) => void) => void;
setParam: (key: string, value: string) => void;
getParam: (key: string) => void;
}
<S>
State type to push in browser history.
Public API | Description |
---|---|
getParamFromURL | Get param value from URL |
getPathnameFromURL | Get path name from URL |
go | Push in browser history |
subscribeOnPopState | Subscribe handler when pop state in history |
params | URL params state |
setParam | Set new param state |
getParam | Get new param state |
// Browser URL "https://example.com/?foo=bar"
import rl from 'erre-ele';
const fooValue = rl.getParamFromURL('foo'); // bar