Open MoAsmar opened 6 years ago
any progress? I have the same problem
Similar issue. While investigating it, I copied your router code:
<div>
<stencil-router root='/apps/hellostencil'>
<stencil-route url='/' component='home' exact={true}>
</stencil-route>
<stencil-route url='/hello' component='hello' exact={true}>
</stencil-route>
</div>
and duplicated the problem.
I removed the <div/>
tag:
<stencil-router root='/apps/hellostencil'>
<stencil-route url='/' component='home' exact={true}>
</stencil-route>
<stencil-route url='/hello' component='hello' exact={true}>
</stencil-route>
I duplicated this after a 'git clone' of the PWA toolkit. I installed the @stencil/router, added an import for the @stencil/router to my-app.tsx and changed all <ion-router>
and <ion-route>
to <stencil-router>
and <stencil-route>
:
<ion-app>
<stencil-router>
<stencil-route url="/" component="app-home" />
<stencil-route url="/profile/:name" component="app-profile" />
</stencil-router>
</ion-app>
and got a blank page.
Following your code above:
<div>
<stencil-router>
<stencil-route url="/" component="app-home" />
<stencil-route url="/profile/:name" component="app-profile" />
</stencil-router>
</div>
I got a blank page.
Removing the <div/>
tag allowed the app to display:
render() {
return (
<stencil-router>
<stencil-route url="/" component="app-home" />
<stencil-route url="/profile/:name" component="app-profile" />
</stencil-router>
);
}
The app now displays. However, there still is no app navigation. I added a stencil-route-link in addition to the existing ion-button, both attempting to go to /profile/ionic. Neither worked.
Thanks @arby50, I solved this one using root attribute on stencil-router element, but still this router isn't mature enough, I am here to add a bug regarding guards.
thanks @arby50!!
Any updates on this issue. I am having the same problem (if I understand it correctly) where my component root (where the main component and router live) is not the root of the application. My navigation only works if the URL resolves from the root of the application, NOT relative to where the component root is located. I thought I could solve it by adding the path to the component root passed down as a prop to each component, but then it doesn't resolve the full path. Here is an example of my router definition.
<stencil-router root={mileOnComponentRoot}>
<stencil-route
url='/'
component="mile-on-trip-list"
componentProps={componentProps}
exact={true}
/>
<stencil-route
url={'/trips/:tripId/stops/:stopId'}
component="mile-on-stop"
componentProps={componentProps}
/>
<stencil-route
url={'/trips/:tripId/map'}
component="mile-on-trip-map"
componentProps={componentProps}
/>
<stencil-route
componentProps={componentProps}
exact={true}
routeRender={() => {
return <h1>Error loading Mile On Trip Planner</h1>;
}}
/>
</stencil-router>
And my attempt at solving the issue by including the component root when pushing via history.
let url = this.mileOnComponentRoot + `/trips/${this.tmsTripId}/stops/${stopId}`;
this.history.push(url);
Any updates? The above solution does work when using the root attribute. The problem with that is that you have to change the root for local dev and production.
I think this might be related to: https://github.com/ionic-team/stencil-router/issues/80#issuecomment-582551305
This works for me:
stencil.conf.js
baseUrl: '/foobar'
main component
<stencil-router root="/foobar/">
<stencil-route-switch>
<stencil-route url="/login" component="demo-login"></stencil-route>
<stencil-route url="/main" component="demo-main"></stencil-route>
</stencil-route-switch>
</stencil-router>
and then navigating with
this.history.push('./main');
With this I can navigate the app on myhost.com/foobar/login or myhost.com/foobar/main resp.
This works for me:
stencil.conf.js
baseUrl: '/foobar'
main component
<stencil-router root="/foobar/"> <stencil-route-switch> <stencil-route url="/login" component="demo-login"></stencil-route> <stencil-route url="/main" component="demo-main"></stencil-route> </stencil-route-switch> </stencil-router>
and then navigating with
this.history.push('./main');
With this I can navigate the app on myhost.com/foobar/login or myhost.com/foobar/main resp.
Your answer solved my problem. It works! 👍🏽
I am working on an app with a few components and trying to put it on my website under a sub-directory:
main component:
stencil.config.js release config:
Index.html
package.json dependencies
After few investigations and failed tries, I figured out how to host my app under a sub-directory by adding 'root' property to and adding baseUrl to the release configs as mentioned above, this makes my home page url works('https://myhost/apps/hellostencil'), but the sub page which is under my sub-directory ('https://myhost/apps/hellostencil/hello') is not working, the component is not being rendered at all, and the stencil route tag is empty!
Also adding a
<stencil-route-link url='/hello'></stencil-route-link>
to my home page as anchor to go to my hello page did not make any difference.Please help!
Note: removing 'root' tag from stencil-route and testing locally (npm start), everything works perfectly!