Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document react router basename for relative builds #2593

Closed
jsk548 opened this issue Jun 22, 2017 · 20 comments
Closed

Document react router basename for relative builds #2593

jsk548 opened this issue Jun 22, 2017 · 20 comments

Comments

@jsk548
Copy link

jsk548 commented Jun 22, 2017

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.

@notrab
Copy link

notrab commented Jun 22, 2017

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?

@viankakrisna
Copy link
Contributor

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]

@Timer
Copy link
Contributor

Timer commented Jun 22, 2017

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. 😄

@Timer Timer closed this as completed Jun 22, 2017
@jsk548
Copy link
Author

jsk548 commented Jun 23, 2017

Hi ,
I tried with that also . default page is showing . when we route to other pages it shows "object not found"

@viankakrisna
Copy link
Contributor

@jsk548 sadly, I cannot help much with that information.

  1. Do you have mod_rewrite extension enabled?
  2. What's the actual response that is coming from the server? (a screenshot of dev tools network tab would be sufficient) Is it 200 or 500?
  3. Can you share the URL where the app deployed?
  4. Do you have access to support for maintaining the server?
  5. Can you configure the Apache vhost file?

@jsk548
Copy link
Author

jsk548 commented Jun 23, 2017

Further more, here is what i found.

  1. i have deployed as - demo1.gd.com/cliq - (which serves the index)
  2. but i have fouind that when i click on products it should take me to demo1.gd.com/cliq/products instead it takes me to demo1.gd.com/products
  3. it is missing the cliq in the url - demo1.gd.com/cliq whch is the host

@viankakrisna
Copy link
Contributor

@jsk548
Copy link
Author

jsk548 commented Jun 23, 2017

@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

@viankakrisna
Copy link
Contributor

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?

@viankakrisna
Copy link
Contributor

@jsk548 btw, I cannot access demo1.gd.com, is it a virtualhost?

@Timer
Copy link
Contributor

Timer commented Jun 23, 2017

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?

@viankakrisna
Copy link
Contributor

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

@viankakrisna
Copy link
Contributor

I just found out that react router v4 supports basename on BrowserRouter though https://reacttraining.com/react-router/web/api/BrowserRouter/basename-string

@Timer
Copy link
Contributor

Timer commented Jun 23, 2017

Oh sweet we should probably suggest the basename feature in react-router then.

@gaearon
Copy link
Contributor

gaearon commented Jun 26, 2017

Anybody want to send a doc PR?

@Timer
Copy link
Contributor

Timer commented Jun 26, 2017

Let's open this because I think it's really important

@Timer Timer reopened this Jun 26, 2017
@Timer Timer changed the title React Routes are not working in Apache server Document react router basename for relative builds Jun 26, 2017
@jsk548
Copy link
Author

jsk548 commented Jun 27, 2017

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.

@viankakrisna
Copy link
Contributor

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.

@jsk548
Copy link
Author

jsk548 commented Jun 28, 2017

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

@viankakrisna
Copy link
Contributor

viankakrisna commented Jun 28, 2017

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

viankakrisna added a commit to viankakrisna/create-react-app that referenced this issue Jun 28, 2017
viankakrisna added a commit to viankakrisna/create-react-app that referenced this issue Jun 28, 2017
Timer pushed a commit that referenced this issue Jun 29, 2017
* Add more info about apache client side routing

After a revelation in #2593 (comment)

* Update README.md
rrdelaney pushed a commit to rrdelaney/reason-scripts that referenced this issue Jul 3, 2017
* Add more info about apache client side routing

After a revelation in facebook/create-react-app#2593 (comment)

* Update README.md
romaindso pushed a commit to romaindso/create-react-app that referenced this issue Jul 10, 2017
* Add more info about apache client side routing

After a revelation in facebook#2593 (comment)

* Update README.md
Timer pushed a commit that referenced this issue Jul 12, 2017
* Docs for react-router v4 basename feature

Fix #2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
wmonk pushed a commit to wmonk/create-react-app-typescript that referenced this issue Aug 7, 2017
* Add more info about apache client side routing

After a revelation in facebook/create-react-app#2593 (comment)

* Update README.md
JohnNilsson pushed a commit to JohnNilsson/create-react-app-typescript that referenced this issue Aug 9, 2017
* Docs for react-router v4 basename feature

Fix facebook/create-react-app#2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
morgs32 pushed a commit to BrickworkSoftware/create-react-app that referenced this issue Sep 1, 2017
* Add more info about apache client side routing

After a revelation in facebook#2593 (comment)

* Update README.md
morgs32 pushed a commit to BrickworkSoftware/create-react-app that referenced this issue Sep 1, 2017
* Docs for react-router v4 basename feature

Fix facebook#2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
JohnNilsson pushed a commit to JohnNilsson/create-react-app-typescript that referenced this issue Sep 9, 2017
* Docs for react-router v4 basename feature

Fix facebook/create-react-app#2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
kasperpeulen pushed a commit to kasperpeulen/create-react-app that referenced this issue Sep 24, 2017
* Docs for react-router v4 basename feature

Fix facebook#2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
swengorschewski pushed a commit to swengorschewski/cra-typescript-electron that referenced this issue Oct 16, 2017
* Docs for react-router v4 basename feature

Fix facebook/create-react-app#2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
rrdelaney pushed a commit to rrdelaney/reason-scripts that referenced this issue May 23, 2018
* Add more info about apache client side routing

After a revelation in facebook/create-react-app#2593 (comment)

* Update README.md
rrdelaney pushed a commit to rrdelaney/reason-scripts that referenced this issue May 23, 2018
* Docs for react-router v4 basename feature

Fix facebook/create-react-app#2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
Coord pushed a commit to Azure/iot-ux-baseline that referenced this issue Jun 29, 2018
* Add more info about apache client side routing

After a revelation in facebook/create-react-app#2593 (comment)

* Update README.md
Coord pushed a commit to Azure/iot-ux-baseline that referenced this issue Jun 29, 2018
* Docs for react-router v4 basename feature

Fix facebook/create-react-app#2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
sven3270350 added a commit to sven3270350/react-typescript that referenced this issue Aug 11, 2022
* Docs for react-router v4 basename feature

Fix facebook/create-react-app#2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
sven3270350 added a commit to sven3270350/react-typescript that referenced this issue Aug 11, 2022
* Docs for react-router v4 basename feature

Fix facebook/create-react-app#2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
OrdinalKing pushed a commit to OrdinalKing/create-react-app-ts-redux-saga-mui that referenced this issue Aug 26, 2022
* Docs for react-router v4 basename feature

Fix facebook/create-react-app#2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
OrdinalKing pushed a commit to OrdinalKing/create-react-app-ts-redux-saga-mui that referenced this issue Aug 26, 2022
* Docs for react-router v4 basename feature

Fix facebook/create-react-app#2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
SmartCodiDev added a commit to SmartCodiDev/redux-saga-mui that referenced this issue May 31, 2024
* Docs for react-router v4 basename feature

Fix facebook/create-react-app#2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
SmartCodiDev added a commit to SmartCodiDev/redux-saga-mui that referenced this issue May 31, 2024
* Docs for react-router v4 basename feature

Fix facebook/create-react-app#2593

* Update README.md

* Update README.md

* Update README.md

* Update README.md
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants