client side routing to component on browser refresh throws 404 error - reactjs

I have a react app created with the create-react-app template and want it be deployed on IIS as a part of another application folder.
On client navigation after loading the navigated component is loaded but when i refresh the url from the browser i get a 404 error
For example:
i build using npm run build with package.json
I have also set the base name to the Router component
on open of the react site and navigation to the component "Admin" it shows the component properly. But when i reload the same url by refreshing from the browser refresh button i get an 404 error page not found.
When i run using the npm start it runs with http://localhost:3000/ as default and on component navigation changes the url to http://localhost:3000/admin . here if i refresh from the browser it loads the page and navigates properly showing the navigated component.
What am i missing to make this work ?

Related

After a refresh, the React App in Netlify crashed

After deploying my React app in Netlify, when I refresh my base url's page, it works, but when I refresh other routes, the app crashes.
I want the browser to load the specific route's contents after refreshing the page.

React router not loading dynamic url in production

I have a url with paramenters in my react routes.
I can access the route via {Link} from react router dom as shown below. The page loads upon button click.
However when I refresh the page or try to access the URL via the address bar, I get a blank page and this error message
It works fine locally but the blank page comes up in production. I am hosting the website on heroku.
The best way to handle it is to add a base tag in your index.html.
<base href="/" />
I fixed the problem using the solution in the link below. I initially set my homepage to "." in my package.json and eventually changed it to my app domain
https://stackoverflow.com/a/66950806/6542175

How to properly fetch data from a Url?

I've created a website using create-react-app and react router. I am able to load the website from https://www.example.com/reactapp but I get a 404 error when I try to access a page like https://www.example.com/reactapp/somePage
The website is running on port 8080, https connection is working, inside my package.json I've defined my homepage as: "https://example.net/reactapp". In my BrowserRouter I've defined my basename as "/reactapp" and links are working and loading the pages just fine.
The thing also is that https://example.net/ displays a wordpress website, when I try to access https://www.example.net/reactapp/somePage I get a 404 error from the wordpress website. How can I properly fetch data when calling for a specific page?
Redirect all requests coming to the server to index.html

My greeting, Some problems with react routing when project hosted

I created react dom routing in my react app. Component navigation works if you run npm start, but if the project is built and hosted, a 404 error occurs during navigation This happens because the hosting requests index.html when the react changes the main html file to (page name) .html during navigation.

Accessing other html files on a cloudfront distribution hosting a react app

I have a react app that's hosted on AWS Cloudfront, and the default root is set to index.html, which loads the react app.
So far so good.
I created a new html page page1.html, and then tried accessing it using the full URL, https://my.site.com/page1.html.
Uh oh.
The React app is loaded, and it's router intercepted the URL, and displayed the page not found error. React has no knowledge of the html page, which sounds about right.
If the cache is cleared the page1.html file loads correctly, however as soon as the react app is loaded, the react router starts intercepting the page1.html URL.
Why is that? I kind of expected the direct URL to load the html file bypassing the react app.
And is there a way to add an exception in react router to allow the page to be loaded without being intercepted?

Resources