TL;DR - I want my React app to start with a relative path domain.com/tweets
Hello everyone, I'm creating a React app that fetches tweets from Twitter API.
Because the whole app is just an SPA built in react, I figured it would be wrong to create an empty homepage with a link to navigate to the tweets page, instead of just displaying the tweets right away as the "homepage". Again, currently, displaying tweets is the only thing the app does.
Therefore, I was looking for a way to start my app with the path "/tweets/" right after the domain name.
I know there are two options I can use but I'm not sure which one to use:
- package.json "homepage": "/tweets" property
- React router Navigate to="/tweets" component
I like the behavior of the redirect more than the package.json homepage option because I don't have a homepage really, it prevents the user from trying to access domain.com and instead redirects them to domain.com/tweets.
#EDIT 1
In your answer, please note I'm using React Router V6, as some of the previous features you may know might not be relevant anymore.
What option should I choose? Am I missing anything? Will this give me problems when uploading to production?
Here's my current solution:
<BrowserRouter>
<Routes>
<Route path="/tweets" element={<App />}>
<Route path=":pageNumber" />
</Route>
<Route
path="*"
element={<Navigate to="/tweets"/>}
/>
</Routes>
</BrowserRouter>
EDIT #2 - Here's the updated code
<BrowserRouter>
<Routes>
<Route path="/tweets/:currentPageNumber" element={<App />}/>
<Route path="/*" element={<Navigate to="/tweets/1" />} />
</Routes>
</BrowserRouter>