I have a static web app (React/Typescript) with the following routes/pages:
index.ts
ReactDOM.render(
<ThemeProvider>
<React.StrictMode>
<Provider store={store}>
<BrowserRouter>
<Routes>
<Route path="" element={<App />}>
<Route path="/" element={<JobsPage />} />
<Route path="/JobDetails" element={<JobDetails />} />
<Route path="/OwnerPage" element={<OwnerPage />} />
<Route path="/AdminConfig" element={<AdminConfig />} />
<Route path="/ManageMembership" element={<ManageMembership />} />
</Route>
</Routes>
</BrowserRouter>
</Provider>
</React.StrictMode>
</ThemeProvider>,
document.getElementById('root')
);
On running locally, I can go to these pages directly. For example, "localhost:3000/ManageMembership"
takes me to ManageMembership
page. After deployment, "abc.com/ManageMembership"
is showing "Not Found". It’s not redirecting to ManageMembership
page. But, if I click a button, I see the URL set to abc.com/ManageMembership
. If I try to access this URL, it shows "Not Found". What am I missing and how do I fix this?
2
Answers
I created a sample React.js application, deployed it to Azure Static Web Apps, and successfully redirected to the specific route.
page not found
error , I’ve added astaticwebapp.config.json
file in the root directory of the project.staticwebapp.config.json
file is required to handle routes.Please add the below staticwebapp.config.json file in your project directory.
My index.tsx:
I’ve successfully deployed the application to Azure static web app via Github actions.
Local output:
Output after deployment:
In App.js
This is simple sample. I use this code, display in localhost:3000. I think importing route is very important , you listen and do like this.