Last active
June 27, 2021 18:11
-
-
Save sawyerh/c0fe0aeeec7f2b91ccf68c2a29f07f65 to your computer and use it in GitHub Desktop.
Router.js: Routing using state machines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// router.js | |
import { routingMachine } from "machine"; | |
export function getNextPathname(event, context) { | |
const currentPathname = window.location.pathname; | |
const nextPathname = routingMachine | |
.withContext(context) // https://xstate.js.org/docs/guides/context.html | |
.transition(currentPathname, event); // https://xstate.js.org/api/interfaces/statemachine.html#transition | |
return nextPathname; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment