S
S
sharkdest2019-04-10 10:44:59
JavaScript
sharkdest, 2019-04-10 10:44:59

How to remove hash(#) from react-router-dom path?

Hello, tell me how to remove # from my path.
Now it's like this: localhost:3000/#/details/test , but it should be localhost:3000/details/test

<HashRouter>
        <div>
          <Route path="/" exact component={Home} />
          <Route path="/details/:service" component={Service} />
        </div>
</HashRouter>

This is how I generate links:
...
{servicesList.map((service, index) => (
                <tr
                  onClick={() => {
                    history.push("/details/" + service);
                  }}
                  key={service}
                >
                  <td>{service}</td>
                </tr>
))}
...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Bogdanov, 2019-04-10
@sharkdest

You are using the HashRouter component, hence the hashes in the address bar. For your task, BrowserRouter is suitable for you. For links, use the Link
component

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question