Created
December 18, 2019 22:00
-
-
Save dvtng/ce1f55df08e6a974ab5d8618bbb202a0 to your computer and use it in GitHub Desktop.
This file contains 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 concepts | |
// - route declaration (abstract) vs. route implementation (concrete) | |
// - transitionIds | |
// - onPrepare, onTransitionStart, onTransitionEnd | |
// - global click handler | |
// - useRouterState, useRouterActions | |
type RouteInfo = { | |
name: string; | |
params: { [key]: string }; | |
query: { [key]: string }; | |
hash: string; | |
} | |
type RouterState = { | |
history: RouteInfo[]; | |
current: RouteInfo; | |
} | |
const VIEW_PAGE = new Route<{ spaceKey: string, contentId: string, slug?: string }>({ | |
// abstract | |
name: "VIEW_PAGE", | |
pattern: "/wiki/spaces/:spaceKey/pages/:contentId/:slug?", | |
condition: (state) => true, | |
// concrete | |
render: (state) => {}, | |
onPrepare: (state) => {}, | |
onTransitionStart: (state) => {}, | |
onTransitionEnd: (state) => {} | |
}); | |
const MyComponent = () => { | |
const { push } = useRouterActions(); | |
return ( | |
<button onClick={() => push(VIEW_PAGE.toUrl({ spaceKey: "CONF", contentId: "123456789" })}> | |
Go to page | |
</button> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment