preactjs / preact-router

:earth_americas: URL router for Preact.
http://npm.im/preact-router
MIT License
1.02k stars 155 forks source link

Typescript hash router error #385

Closed sriksm19 closed 2 years ago

sriksm19 commented 4 years ago

tried using the snippet given in the example for custom history (i need it for the hash-router). getting the following typescript error

image

rschristian commented 4 years ago

I assume you're using history as the snippet is? If so, the snippet was written before history released v5, and I assume that's what you're using. You can downgrade to history v4 if you'd like to keep using it. v5's types are incompatible with this library.

sriksm19 commented 4 years ago

oh. thank you!

rschristian commented 4 years ago

It might be worth keeping this open for visibility.

I'll try to whip up a quick PR tomorrow to get some more detail in the ReadMe. Hopefully will help people avoid this pitfall.

rzhq commented 3 years ago

I wrote an adapter if you really want to use history v5

import { HashHistory } from 'history';
import { CustomHistory } from 'preact-router';

export const hashHistoryAdapter = (hashHistory: HashHistory): CustomHistory => {
  return {
    listen: (callback) => hashHistory.listen(({ location }) => callback(location)),
    location: hashHistory.location,
    push: hashHistory.push,
    replace: hashHistory.replace
  };
};
rschristian commented 2 years ago

Support for v5 was added in #410