Skip to content

Instantly share code, notes, and snippets.

@bkspace
Created October 14, 2020 14:54
Show Gist options
  • Save bkspace/68d300444441044f564b02241b7f1168 to your computer and use it in GitHub Desktop.
Save bkspace/68d300444441044f564b02241b7f1168 to your computer and use it in GitHub Desktop.
Shopify admin route propagator
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
@ctrlaltdylan
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment