Skip to content
Advertisement

Adding Base URL in react.js project is not working

I want to add the base URL to my react.js project. However I had tried couple of methods that did not work.

For example, if my project url is :

JavaScript

It should appear in address bar as :

JavaScript

Below is my project code.

index.js

JavaScript

App.js

JavaScript

What I had tried?

As I referred in stackoverflow and also many other websites, integrated below methods.

  1. Added base url inside package.json file
    "homepage": "/app",
  2. Tried to pass the tag <base href="http://myapp.com/app"> within <head> tag in public/index.html page
  3. Passed the base url within BrowserRouter in index.js <BrowserRouter basename="app"> </BrowserRouter>

I am sure I am missing something, it would be great learning if someone help on this or give insights on this.

Thank you

Advertisement

Answer

I don’t know the correct answer to this , but I believe that you can redirect the route “/” to “/app” . I hope this can help you

Advertisement