Created
October 14, 2020 14:54
-
-
Save bkspace/68d300444441044f564b02241b7f1168 to your computer and use it in GitHub Desktop.
Shopify admin route propagator
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
import { useEffect, useContext } from 'react' | |
import Router, { useRouter } from 'next/router' | |
import { Context as AppBridgeContext } from '@shopify/app-bridge-react' | |
import { Redirect } from '@shopify/app-bridge/actions' | |
import { RoutePropagator as ShopifyRoutePropagator } from '@shopify/app-bridge-react' | |
const RoutePropagator = () => { | |
const router = useRouter() | |
const { route } = router | |
const appBridge = useContext(AppBridgeContext) | |
useEffect(() => { | |
const unsub = appBridge.subscribe(Redirect.ActionType.APP, ({ path }) => { | |
Router.push(path) | |
}) | |
return () => unsub() | |
}) | |
return appBridge && route ? <ShopifyRoutePropagator location={route} /> : null | |
} | |
export default RoutePropagator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome, found this other implementation as I was googling around: Shopify/shopify-app-template-node#148
Only different I see is the dependencies on the
useEffect
hook.