1

I am new to react. I would like to implement react router as hash url. For Example I need a url #/list in react-router but by default react uses /list url. How can I implement hash url in react ?

1 Answer 1

5

You can make use of a HashURL, by making use of HashRouter instead of BrowserRouter for your router config

import { HashRouter, Route } from 'react-router-dom';

render() {
    return <HashRouter>
         <Route path="/" component={Home} />
    </HashRouter>

}

In case you are using a react-router v3 or lower, you would specify hashHistory to Router

import { Router, Route, hashHistory } from 'react-router';

render() {
    return <Router history={hashHistory}>
         <Route path="/" component={Home} />
    </Router>

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.