I am developing my application using the node.js template and hosted on ngrok.
Whenever I refresh the page, the entire application is restarted and I am therefore put back to the home page?
This has been happening the entire time, is there some specific setup or is there something in my code that’s wrong?
Thanks!
App.tsx
import {
BrowserRouter as Router,
Routes,
Route,
useLocation,
useNavigate,
Navigate,
createBrowserRouter
} from "react-router-dom";
import {
ApolloClient,
ApolloProvider,
HttpLink,
InMemoryCache,
} from "@apollo/client";
import {
Provider as AppBridgeProvider,
useAppBridge,
} from "@shopify/app-bridge-react";
import { authenticatedFetch } from "@shopify/app-bridge-utils";
import { Redirect } from "@shopify/app-bridge/actions";
import {
AppProvider as PolarisProvider,
Frame,
Layout,
Page,
} from "@shopify/polaris";
import translations from "@shopify/polaris/locales/en.json";
import "@shopify/polaris/build/esm/styles.css";
import { Provider } from "react-redux";
import { store } from "./redux/store";
import { HomePage } from "./components/HomePage";
import { CampaignDashboard } from "./components/campaign/CampaignDashboard";
import CreateCampaignContainer from "./components/campaign/CreateCampaignContainer";
import { useEffect, useState } from "react";
import { CreateCampaignComponent } from "./components/campaign/CreateCampaign";
export default function App() {
return (
);
}
function MyProvider({ children }) {
const app = useAppBridge();
const client = new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({
credentials: "include",
fetch: userLoggedInFetch(app),
}),
});
return ;
}
export function userLoggedInFetch(app) {
const fetchFunction = authenticatedFetch(app);
return async (uri, options?) => {
const response = await fetchFunction(uri, options);
if (
response.headers.get("X-Shopify-API-Request-Failure-Reauthorize") === "1"
) {
const authUrlHeader = response.headers.get(
"X-Shopify-API-Request-Failure-Reauthorize-Url"
);
const redirect = Redirect.create(app);
redirect.dispatch(Redirect.Action.APP, authUrlHeader || `/auth`);
return null;
}
return response;
};
}
index.tsx
import { createRoot } from 'react-dom/client';
import { BrowserRouter } from "react-router-dom";
import App from "./App";
const container = document.getElementById('app');
const root = createRoot(container);
root.render(
);