question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

this.history is undefined with injectHistory

See original GitHub issue

Resources: https://stenciljs.com/docs/router-tutorials#inject-history-into-a-deep-component

Stencil version::

@stencil/core@0.15.2

I’m submitting a … [x] bug report [ ] feature request [ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://stencil-worldwide.slack.com

Current behavior: this.history is undefined in a deep component

Expected behavior: this.history is not undefined

Steps to reproduce: All steps from https://stenciljs.com/docs/router-tutorials#inject-history-into-a-deep-component

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:7
  • Comments:10

github_iconTop GitHub Comments

4reactions
FabianEbertcommented, Mar 24, 2020

I could not reproduce the issue on my side with stencil-router 1.0.1.

I needed to navigate programmatically in some component of my application which is not rendered by a stencil-route and followed this wiki article. To have the history() property defined, you need to additionally inject the history, the wiki article was not complete here.

So my full components looks like this now:

import { RouterHistory, injectHistory } from '@stencil/router'; // version 1.0.1

export class MyComponent {
  @Prop() history: RouterHistory;
  
  @Listen('my-custom-event')
  handleMyCustomEvent(event: CustomEvent) {
    this.history.push(event.detail.route, {});
  }
}

injectHistory(MyComponent);
1reaction
carbonfishcommented, Nov 7, 2019

Still not working

Read more comments on GitHub >

github_iconTop Results From Across the Web

this.history is undefined with injectHistory · Issue #79 · stencil ...
Tried to debug this issue and found that function that creates Provider is copied in bundle 2 times, hence we have two copies...
Read more >
javascript - How to pass 'history' object to stencil.js component ...
However I'm completely unable to injectHistory(Appnav) to the component, according to some tuorials I followed. Always I get an undefined log. Structure as ......
Read more >
React router v5 - TypeError history is undefined
Unfortunately, I was receiving TypeError: history is undefined every button was pressed. It took me a while, but the fix was trivial.
Read more >
React Router - How to pass History object to a component
Do you mind explaining why this.props.history.push("/home") might result in undefined but this would work? I think it has something to do with ...
Read more >
React Router, why useLocation and useHistory might return ...
const history = useHistory() const location = useLocation(). They both returned undefined . Turns out I was adding the Router to the DOM ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found