I'm working with an embedded React Shopify app (bootstrapped with create-react-app). I'm trying to follow the docs for the ClientRouter component in app-bridge-react: https://shopify.dev/tools/app-bridge/react-components/client-router but I'm fairly new to the Shopify ecosystem, and I can't seem to get the embedded routing to communicate with the navigation links set up in Shopify. The examples in the docs don't show how routing should look inside the React app.
// index.js
import React from 'react'
import ReactDOM from 'react-dom'
import { BrowserRouter } from 'react-router-dom'
import { Provider as AppBridgeProvider } from '@shopify/app-bridge-react'
import { AppProvider } from '@shopify/polaris'
import translations from '@shopify/polaris/locales/en.json'
import '@shopify/polaris/styles.css'
import Router from './Router'
import './index.css'
ReactDOM.render(
<React.StrictMode>
<BrowserRouter>
<AppBridgeProvider
config={{
apiKey: API_KEY,
shopOrigin: SHOP_ORIGIN,
}}
>
<AppProvider i18n={translations}>
<Router />
</AppProvider>
</AppBridgeProvider>
</BrowserRouter>
</React.StrictMode>,
document.getElementById('root')
)
// Router.js
import { withRouter } from 'react-router-dom'
import { useClientRouting } from '@shopify/app-bridge-react'
const Router = (props) => {
const { history } = props
console.log(history.location) // always "/"
useClientRouting(history)
return null
}
export default withRouter(Router)
I've tried returning a Switch with routes inside of Router.js, but the history location is always "/" (though I can see the URL changing in the iframe). Any help would be appreciated.