Create /components/ClientRouter.js
import { withRouter } from 'next/router';
import { ClientRouter as AppBridgeClientRouter } from '@shopify/app-bridge-react';
function ClientRouter(props) {
const { router } = props;
return <AppBridgeClientRouter history={router} />;
}
export default withRouter(ClientRouter);
Create /components/RoutePropagator.js
import { useEffect, useContext } from 'react';
import Router, { useRouter } from 'next/router';
import { Context as AppBridgeContext, useRoutePropagation } from '@shopify/app-bridge-react';
import { Redirect } from '@shopify/app-bridge/actions';
import { RoutePropagator as AppBridgeRoutePropagator } from '@shopify/app-bridge-react';
const RoutePropagator = ({ path }) => {
const router = useRouter();
const { route } = router;
const appBridge = useContext(AppBridgeContext);
useEffect(() => {
appBridge.subscribe(Redirect.Action.APP, ({ path }) => {
Router.push(path);
});
}, []);
return appBridge && route ? <AppBridgeRoutePropagator location={route} /> : null;
};
export default RoutePropagator;
Add provider to app:
import ClientRouter from '../components/ClientRouter';
import RoutePropagator from '../components/RoutePropagator';
<React.Fragment>
<ApolloClientProvider>
<AppBridgeProvider config={config}>
<ClientRouter />
<RoutePropagator />
...
</AppBridgeProvider>
</ApolloClientProvider>
</React.Fragment>