A
A
Anton Myasnov2020-04-17 21:05:33
React
Anton Myasnov, 2020-04-17 21:05:33

How to setup react route and navlink properly?

Good day. Please tell me what am I doing wrong.
Created a project with create-react-app using react router.
Locally everything works fine and switches as it should.
configured like this

<Switch>
          <Route path="/" exact component={Home} />
          <Route path="/messages" component={Messages} />
          <Route path="/notification" component={Notification} />
          <Route path="/settings" component={Settings} />
</Switch>

The links themselves
<NavLink  to="/">Link</NavLink>
<NavLink  to="/messages">Link</NavLink>
<NavLink  to="/notification">Link</NavLink>
<NavLink  to="/settings">Link</NavLink>

Uploaded to the server in the nested folder domain.ru/works/project-name
In package.json I wrote "homepage": " domain.ru/works/project-name "
Everything loads well, but.
1) The Home component is not loaded, which should be loaded by default, other links work.
2) If you change the first route to <Route path="" exact component={Home} />then the Home component is loaded, but other links stop working
. Also, the address in the address bar when you click the link changes domain.ru/notification or another component name, although it should change to " domain.ru/works/project-name /notification " and refreshing the page, I won't get the page I was on.
Where did I go wrong and what did I spell wrong?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2020-04-17
@MambliJoe

There are several options, you choose - read here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question