作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个没有框架的 Ionic 4 PWA(所以请不要使用 Angular 答案),我需要弄清楚如何使用 ion-router 和 ion-route 组件。我想我了解 url 路由应该如何工作,尽管我很难看到如何设置它以在单击按钮时显示正确的页面。我认为问题在于我不知道您如何引用要显示的“组件”。
在 ion-route 元素的 JS 文档中,它说 components 属性是:
Name of the component to load/select in the navigation outlet (ion-tabs, ion-nav) when the route matches.
The value of this property is not always the tagname of the component to load, in ion-tabs it actually refers to the name of the ion-tab to select.
<ion-router>
<ion-route component="page-tabs">
<ion-route url="/schedule" component="tab-schedule">
<ion-route component="page-schedule"></ion-route>
<ion-route url="/session/:sessionId" component="page-session"></ion-route>
</ion-route>
<ion-route url="/speakers" component="tab-speaker">
<ion-route component="page-speaker-list"></ion-route>
<ion-route url="/session/:sessionId" component="page-session"></ion-route>
<ion-route url="/:speakerId" component="page-speaker-detail"></ion-route>
</ion-route>
<ion-route url="/map" component="page-map"></ion-route>
<ion-route url="/about" component="page-about"></ion-route>
</ion-route>
<ion-route url="/tutorial" component="page-tutorial"></ion-route>
<ion-route url="/login" component="page-login"></ion-route>
<ion-route url="/account" component="page-account"></ion-route>
<ion-route url="/signup" component="page-signup"></ion-route>
<ion-route url="/support" component="page-support"></ion-route>
</ion-router>
例如,我不明白组件“页面支持”的定义位置 - 它是一个名为 page-support.html 的文件还是文件中的一个元素?
最佳答案
好的,所以我做了一些研究,发现要定义一个组件,您需要先定义一个自定义元素,如下所示:
customElements.define('new-page', class extends HTMLElement {
connectedCallback() {
this.innerHTML = `
<ion-header>
<ion-toolbar>
<ion-title>Page Header</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">
Page Content
</ion-content>`;
}
});
<ion-route url="/newpage" component="new-page"></ion-route>
关于javascript - 如何在 Vanilla Ionic 4 中使用 ionic 路由器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58491130/
我是一名优秀的程序员,十分优秀!