React Router URLs (Learning React)

Quick question about React Router and urls from the book “Learning React”. When I code the demo, the urls that the router produces are shown below:
https://jamesallan626.gitlab.io/reactspa/#/ . (Home ‘page’)
https://jamesallan626.gitlab.io/reactspa/#/packages (Packages ‘page’)
https://jamesallan626.gitlab.io/reactspa/#/contact (Contact ‘page’)
These are odd looking especially with the ‘#’ character.
My question is can we do better? (ie. can get get rid of the # and make the urls more friendly?)

You can set your history to use browserHistory. I think by default it uses hashHistory which includes the hash (#) in the url. Using the browser’s history API allows the URL to change without using the hash (and not causing the page to reload).

https://github.com/ReactTraining/react-router/blob/v3/docs/API.md#router

1 Like