Skip to content

Preact Router is not able to be extended #264

@studentIvan

Description

@studentIvan

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
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions