preact-router icon indicating copy to clipboard operation
preact-router copied to clipboard

Preact Router is not able to be extended

Open maslowivan opened this issue 7 years ago • 0 comments

In my case I have to modify the preact router, to make it supports my own functions/behaviour/etc.

I can't do it right now:

  1. initEventListeners will always be called
  2. I can't write my own route function
  3. I can't write my own setUrl function

example code demonstrating the problem

import PreactRouter from 'preact-router';

export default class ExtendedPreactRouter extends PreactRouter {
  constructor(props) {
    super(props); // can't do it without it
    if (props.history) {
      setCustomHistory(props.history); // original code will throw me the error
      // even if I have exported the customHistory variable
    }

    this.state = {
      url: props.url || getCurrentUrl(),
    };

    // initEventListeners(); by the way it will be called, even if commented
  }
}

maslowivan avatar Jan 27 '18 21:01 maslowivan