@algolia/instantsearch-pattern-router

    1.0.1 • Public • Published

    @algolia/instantsearch-pattern-router

    A router for instantsearch which allows simple URLs to be written in the path! Compatible with:

    • InstantSearch.js v3+
    • Vue InstantSearch v2+
    • Angular InstantSearch v2+
    // either via import:
    import { patternRouter, windowEnvironment } from 'instantsearch-pattern-router';
    // or via umd:
    const { patternRouter, windowEnvironment } = window.instantsearchPatternRouter;
    
    instantsearch({
      routing: {
        router: patternRouter({
          pattern: '/search/:hierarchy*/c/category?',
          environment: windowEnvironment,
          // optional
          windowTitle: ({ category }) => `My Site Search — ${category}`,
          writeDelay: 400,
        }),
        // required to flatten to one level
        stateMapping: myFlattenMapping,
      },
    });

    options

    Pattern string

    A pattern is a string of segments, more detailed examples can be found on the path-to-regexp documentation.

    Environment object

    Environment is an option to make this package usable in the browser, but also in other environments, like server-side rendering. The keys that are expected are:

    type Environment = {
      read: () => URL;
      pushState: History['pushState'];
      events?: {
        addEventListener(
          type: 'popstate',
          listener: (this: Window, ev: PopStateEvent) => any
        ): void;
        removeEventListener(
          type: 'popstate',
          listener: (this: Window, ev: PopStateEvent) => any
        ): void;
      };
      setTitle?: (title?: string) => void;
    };

    title function (optional)

    A function that retrieves the current RouteState object

    writeDelay number (optional)

    The number of ms to debounce writing to the URL to maintain performance (writing on every keystroke slows down a site considerably). Default is 500ms.

    Install

    npm i @algolia/instantsearch-pattern-router

    DownloadsWeekly Downloads

    6

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    12.9 kB

    Total Files

    8

    Last publish

    Collaborators

    • spy-seth
    • alejandrouda
    • thomaslef
    • lukyvj
    • sepehrf
    • kosai106
    • marielaure
    • mthuret
    • haroenv
    • rayrutjes
    • speedblue
    • jerska
    • raphi
    • cbaptiste
    • ronanlevesque
    • samouss
    • therealwebby
    • francoischalifour
    • jonmontane
    • mikaa123
    • valentindotxyz
    • shipow
    • tkrugg
    • seafoox
    • sylvainh
    • clemfromspace
    • lorrissaintgenez
    • broujo
    • marieglr
    • e-krebs
    • eunjae-lee
    • kombucha
    • h1fra
    • sylvain
    • crawler-team
    • amcdaid106
    • devinalgolia
    • dispix
    • jvenezia
    • otomatik
    • julienbourdeau
    • sophiem03
    • mschreiber
    • sarahdayan
    • alexandremeunier
    • dcoates
    • maximehuang
    • netgusto
    • guitek
    • matthewbond
    • cyril.descossy
    • tatsuro
    • danajeremy
    • mathougui
    • xavdh
    • agdavid
    • charbell
    • rasemotte
    • plnech
    • shortcuts
    • praagyajoshi
    • loicsay
    • svensoldin
    • alphonseb
    • leodau
    • fabienmotte
    • sarahfranc
    • millotp