简体   繁体   中英

remove # from url react-router-dom in react js

I am new in react.js I am using react-router-dom v6 and I working on a theme where I find an issue with # in URL

Example:- {url}/#/dashboard

I want Example:- {url}/dashboard

am assuming, you are using HashRouter if yes then please use BrowserRouter instead HashRouter

implement BrowserRouter on routing

import { BrowserRouter,Route, Routes } from 'react-router-dom'
render(
<BrowserRouter>
<Routes>....</Routes>
</BrowserRouter>)

You have to use BrowserRouter instead of HashRouter from react-router-dom

In your App.js file, try like below.

import { BrowserRouter, Routes, Route } from 'react-router-dom';
import LandingPage from './Containers/LandingPage';

const App = () => {
  return (
    <BrowserRouter className='App'>
      <Routes>
        <Route exact path='/' element={<LandingPage />} />
      </Routes>
      <Routes>
        <Route ... ... />
      </Routes>
      ... ...
    </BrowserRouter>
  );
}

export default App;
I think you have to use BrowserRouter instead of HashRouter

1. You can add it in your index.js or index.tsx depending on your project.

import { BrowserRouter } from 'react-router-dom'

root.render(
<BrowserRouter>
<App/>
</BrowserRouter>)

2. You can also add in your App.js or App.tsx depending 

import { BrowserRouter,Routes,Route } from 'react-router-dom'

const App = () => {
  return (
    <BrowserRouter className='main'>
      <Routes>
        <Route exact path='/' element={<Home />} />
      </Routes>
      <Routes>
      </Routes>
    </BrowserRouter>
  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM