0

trying to get up and running with react-router on typescript. I have installed @types/react-router, but I am having an issue with an error that reads:

@types/react-router/index"' has no exported member 'hashHistory'

I have been trying different versions of router and the types. My current versions are:

react:  16.3.2
react-router: 4.2.0
@types/react-router: 4.0.23

I have looked at the typings project on github. The index.ds.ts does not show hashHistory being exported. However, there is a v3 folder, and the index.ds.ts there does.

I'm hoping that I just having found that magical mixture of versions for all involved packages.

1 Answer 1

2

In react-router 4, there are separate packages for web, native and core. You need to install react-router-dom instead of react-router (docs)

Also,

With React Router v4, one of the big changes is that there are a number of different router components. Each one will create a history object for you. The <BrowserRouter> creates a browser history, the <HashRouter> creates a hash history...

So instead of passing a history object to the Router, you can just use the HashRouter.

import { HashRouter as Router } from 'react-router-dom'

Documentation on HashRouter

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.