I have a question regarding the use of component properties when routing programmatically.
I’ve trimmed down the Ionic-PWA-Toolkit sample to following code blocks:
my-app.tsx
import '@ionic/core';
import '@stencil/core';
import { Component } from '@stencil/core';
@Component({
tag: 'my-app',
styleUrl: 'my-app.scss'
})
export class MyApp {
render() {
return (
<ion-app>
<main>
<stencil-router>
<stencil-route url='/' component='app-home' exact={true}>
</stencil-route>
<stencil-route url='/profile/:name' component='app-profile'>
</stencil-route>
</stencil-router>
</main>
</ion-app>
);
}
}
app-home.tsx
import { Component, Prop } from '@stencil/core';
import { RouterHistory } from '@stencil/router';
@Component({
tag: 'app-home',
styleUrl: 'app-home.scss'
})
export class AppHome {
@Prop() history: RouterHistory;
handleClick() {
this.history.push("/profile/CatInTheHat", {
thingOne: "Thing 1",
thingTwo: "Thing 2"
});
}
render() {
return (
<ion-page>
<ion-header>
<ion-toolbar color='primary'>
<ion-title>Ionic PWA Toolkit</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<p>
Welcome to the Ionic PWA Toolkit.
</p>
<ion-button onClick={this.handleClick.bind(this)}>
Profile page
</ion-button>
</ion-content>
</ion-page>
);
}
}
app-profile.tsx
import { Component, Prop } from '@stencil/core';
import { MatchResults } from '@stencil/router';
@Component({
tag: 'app-profile',
styleUrl: 'app-profile.scss'
})
export class AppProfile {
@Prop() match: MatchResults;
@Prop() thingOne: string;
@Prop() thingTwo: string;
render() {
if (this.match && this.match.params.name) {
return (
<ion-page>
<ion-header>
<ion-toolbar color='primary'>
<ion-title>Ionic PWA Toolkit</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<p>
Hello! My name is {this.match.params.name}.
My name was passed in through a route param!
And these are my friends, {this.thingOne} and {this.thingTwo}.
</p>
</ion-content>
</ion-page>
);
}
}
}
I was expecting that this.history.push(…) with the object I’m passing in would set the properties in app-profile, but nothing comes across. What am I doing wrong?
Thanks!