Hello I am experimenting with react router, I have developed 3 "pages" and I want to deploy this app to a server at a subdomain. My problem is that I cannot make the react router to work as I expected. I want my app to work at a particular URL. I am not sure if have understood the principles of routing correctly. I am making my test on XAMP. I have implemented a basic react router through browserRouter but I have several issues.
To begin with here is my main component and the routing:
<Router >
<nav className='blue-grey darken-3'>
<div className="blue-grey darken-3nav-wrapper">
<ul id="nav-mobile" className="">
<li><Link to="/">Home</Link></li>
<li><Link to="/creation">Creation form</Link></li>
</ul>
</div>
</nav>
<div className='mainContainer'>
<Switch>
<Route exact path="/">
<HomePageComponent/>
</Route>
<Route exact path="/user/:id">
<UserPageComponent/>
</Route>
<Route path="/creation">
<UserCreationPageComponent/>
</Route>
</Switch>
</div>
</Router>
I have deployed my app to a localhost subdomain called
/reactTest
so the I access the app using
localhost/reactTest
If I navigate around using the links in the app everything works as expected. However I have several problems:
I was expecting that if I would access a url like directly on the browser localhost/reactTest/creation
, I would be navigated to the creation component. Instead I receive a 404 error.
Also, when I navigate using the app's links I see that the domain is discarded. So for example when I click the creation page link, instead of navigating to localhost/reactTest/creation
I am navigated to localhost/creation which works fine, though it doesn't seem correct to me. Again if try to navigate to it be accessing it directly from the browser it doesn't work.
I also tried to set basename to the router by replacing <Router >
with <Router basename="/reactTest">
. That solved the issue with the 'vanishing' subdomain so I was correctly navigated to a page withought losing the 'reactTest' part of the url, but accessing it outside the app still isn't possible.
Is all that the expected behaviour? Is there a way to achieve navigation the way I describe it above?
Thank you in advance,