@stackflow/plugin-history-sync
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

@stackflow/plugin-history-sync

Synchronizes the stack state with the current browser's history

Usage

import { stackflow } from "@stackflow/react";
import { historySyncPlugin } from "@stackflow/plugin-history-sync";
import { MyHome } from "./MyHome";
import { MyArticle } from "./MyArticle";
import { NotFoundPage } from "./NotFoundPage";

const { Stack, useFlow } = stackflow({
  activities: {
    MyHome,
    MyArticle,
    NotFoundPage,
  },
  plugins: [
    // ...
    historySyncPlugin({
      routes: {
        /**
         * You can link the registered activity with the URL template.
         */
        MyHome: "/",
        MyArticle: "/articles/:articleId",
        NotFoundPage: "/404",
      },
      /**
       * If a URL that does not correspond to the URL template is given, it moves to the `fallbackActivity`.
       */
      fallbackActivity: ({ context }) => "NotFoundPage",
      /**
       * Uses the hash portion of the URL (i.e. window.location.hash)
       */
      useHash: false,
    }),
  ],
});

Readme

Keywords

none

Package Sidebar

Install

npm i @stackflow/plugin-history-sync

Weekly Downloads

620

Version

1.4.0

License

MIT

Unpacked Size

180 kB

Total Files

49

Last publish

Collaborators

  • orionmiz
  • irrationnelle
  • tonyfromundefined