Stencil: this.history is undefined with injectHistory

Created on 25 Nov 2018  路  9Comments  路  Source: ionic-team/stencil

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

Stencil version::

@stencil/[email protected]

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

triage

Most helpful comment

Any updates on this? Having the same issue.

All 9 comments

Any updates on this? Having the same issue.

Hello guys, same issue, a bit blocking, had to hack to bypass this and it's not even a proper UX.

@numerized can you please share your workaround? I'm blocked by this as well :(

Never mind me - my component wasn't wrapped within <stencil-router> 馃槄

It appears that history will only be set on components that are selected inside the <stencil-route-switch> component. For example, if I have a URL /my-page-component matching my-page-component, history will be available. But any other component outside of that component won't have its history prop set.

This poses a challenge for me, because I have a layout component that has a left-menu component that sits outside my page components (which themselves are wrapped by <stencil-route-switch>.

Not even rendering a <stencil-route-redirect> component works when being rendered from a component outside of <stencil-route-switch>. Is this by design? Any chance we can make routing work from components that are outside of <stencil-route-switch>? 馃

Turns out there's already a feature request for this here: https://github.com/ionic-team/stencil-router/issues/99

I was able to work around my issue as follows: https://github.com/ionic-team/stencil-router/issues/99#issuecomment-520242489

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anthonylebrun picture anthonylebrun  路  3Comments

cjorasch picture cjorasch  路  3Comments

MatanYadaev picture MatanYadaev  路  3Comments

bekliev picture bekliev  路  3Comments

kensodemann picture kensodemann  路  3Comments