Closed jsk548 closed 7 years ago
Are you using React Router?
If so, I'd check the configuration. Also you'll need to catch all your path requests to go to index.html
so the router can take over.
Are you able to share your code?
Have you done https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#serving-apps-with-client-side-routing ? tldr creating .htaccess file beside index.html with this content usually do it to me.
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
I'll go ahead and close this because we have a section in our documentation which explains how to do this. @viankakrisna has been kind enough to copy this section for you here. 😄
Hi , I tried with that also . default page is showing . when we route to other pages it shows "object not found"
@jsk548 sadly, I cannot help much with that information.
Further more, here is what i found.
It means that you need to set homepage field in the package.json https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#building-for-relative-paths
@viankakrisna samething happening. i added "homepage": "demo1.gd.com/cliq" in package.json no change from previous build. it takes me to demo1.gd.com/products
you need to update your link like this:
<Link to={`${process.env.PUBLIC_URL}/products`}>Products</Link>
@gaearon @Timer I think it's missing from docs? Also, do
<head>
<base href="%PUBLIC_URL%">
...
</head>
in index.html will solve it?
@jsk548 btw, I cannot access demo1.gd.com, is it a virtualhost?
We're hesitant to put the public URL fix in the docs because it might be changing in the future. The HTML base tag looks promising. What kind of browser support does that have?
It's an old spec. So it's pretty well supported. It has gotcha though https://stackoverflow.com/questions/1889076/is-it-recommended-to-use-the-base-html-tag
mainly behavior of <a href="#blabla">
and crawlers are not really good with base tag enabled html
I just found out that react router v4 supports basename on BrowserRouter though https://reacttraining.com/react-router/web/api/BrowserRouter/basename-string
Oh sweet we should probably suggest the basename feature in react-router then.
Anybody want to send a doc PR?
Let's open this because I think it's really important
Is there a solution guys?
I tried above solution you mentioned <Link to={${process.env.PUBLIC_URL}/products
}>Products. But the thing process.env.PUBLIC_URL is always empty.
If you are using react router v4, just use the basename feature linked above. If not, can you share a reproducible example? It's easier to work with code rather than guessing what is wrong.
Hi @viankakrisna , basename is working in localhost but not in apache server. URL http://demo01.gendevs.com/mypro is showing home page. but when i route to http://demo01.gendevs.com/mypro/contactus it shows 404 Object not found https://www.dropbox.com/s/owax5grpvchg8b7/example_router4.zip?dl=0
aaah, you are using apache tomcat, the guide is specifically for Apache HTTP Server with support for .htaccess
. For Apache Tomcat, I think this SO answer will help https://stackoverflow.com/a/41249464/4878474
Hi ,
I have created a demo project and deployed to Apache server but React Routes are not working. When i click on product it should go to "/product" but here it shows object not found. Could you please give permanent solution for this.