stenciljs 学习七 路由
stenciljs路由类似react router
安装
npm install @stencil/router --save
使用
导入包
import "@stencil/router"
添加路由组件配置
包含的组件
- stencil-router
项目中应该只有一个模板路由器组件。此组件控制与浏览器历史记录的所有交互,
并通过事件系统聚合更新 - stencil-route
此组件基于提供的URL是否与当前位置匹配来呈现。
包含的属性
url (Array||string) 同时可以传递参数 /foo/:bar
component (string) 组件名称
componentProps (组件的属性)包含传递给组件渲染的数据
routeRender (function) 接受属性作为参数的函数。如果存在,则将使用它来代替定义的组件
exact (boolean) 如果为true,则只有当url与该地址完全匹配时才呈现此路由,如果为false,则在当前url'匹配'定义的url时呈现
- stencil-route-link
此组件用于渲染指向已定义路由的链接。可以与当前地址是否匹配应用特定样式。
包含的属性
url (string) 连接的路径
exact (boolean) 如果为true,则只有当url与该地址完全匹配时才应用activeclass
activeClass (string) 匹配时候应用的css效果
- stencil-route-redirect
url 地址重定向
配置路由
<stencil-router>
<stencil-route url="/" component="landing-page" exact={true}/>
<stencil-route url="/demos" component="demos-page"/>
<stencil-route url="/demos/rendering" component="fiber-demo"/>
<stencil-route url="/docs" component="docs"/>
<stencil-route url="/docs/getting-started" component="getting-started"/>
<stencil-route url="/components" component="basics-components"/>
</stencil-router>
导航
- 静态导航
使用 stencil-route-link
<stencil-route-link url="/">
<stencil-route-link url="/demos">
<stencil-route-link url="/docs/getting-started">
- 编程方式
import 操作方法
import { RouterHistory } from '@stencil/router';
export class askPage {
@Prop() history: RouterHistory;
}
包含的方法
// pushing a route (going forwards to a certain route)
this.history.push(`/demos`, {});
// navigate back as if the user hit the back button in the browser
this.history.goBack();
// navigate forwards as if the user hit the forwards button in the browser
this.history.goForward();
// replace the current nav history and reset to a certain route
this.history.replace('/', {});
// navigate through the history stack by `n` entries
this.history.go(n: number);
url 参数
- 传递的方式
<stencil-route url='/show/:pageNum' component='show-page' />
<stencil-route-link url={`/show/${someData}`} />
- 组件获取参数
import { MatchResults } from '@stencil/router';
...
export class ShowPage {
@Prop() match: MatchResults;
}
const myData = this.match.params.pageNum;
说明
最简单的方式,可以直接使用脚手工具,创建app,包含router demo
参考资料
https://stenciljs.com/docs/router/
stenciljs 学习七 路由的更多相关文章
- MyBatis学习七:spring和MyBatis整合
<\mybatis\day02\16mybatis和spring整合-sqlSessionFactory配置.avi;> MyBatis学习七:spring和MyBatis整合.逆向工程 ...
- SVG 学习<七> SVG的路径——path(1)直线命令、弧线命令
目录 SVG 学习<一>基础图形及线段 SVG 学习<二>进阶 SVG世界,视野,视窗 stroke属性 svg分组 SVG 学习<三>渐变 SVG 学习<四 ...
- day 85 Vue学习七之vue-cookie
Vue学习七之vue-cookie 通过vue如何操作cookie呢 参考链接:https://www.jianshu.com/p/535b53989b39 第一步:安装vue-cookies ...
- (转)MyBatis框架的学习(七)——MyBatis逆向工程自动生成代码
http://blog.csdn.net/yerenyuan_pku/article/details/71909325 什么是逆向工程 MyBatis的一个主要的特点就是需要程序员自己编写sql,那么 ...
- Django学习之路由分发和反向解析
原 Django学习之路由分发和反向解析 2018年07月12日 14:04:55 huangql517 阅读数 519 1>路由分发 我们之前学习的路由配置都是在项目的全局控制文件(项目名称目 ...
- nodejs学习笔记<七> 路由
// 引用模块(与C#中命名空间,Java中引用包同理) var http = require("http"); var path = require("path&quo ...
- stenciljs 学习十二 官方doc 路由使用的例子
路由在单页面应用开发中是一个相对比较重要的位置 以下为官方网站的路由配置 <stencil-router scrollTopOffset={0}> <stencil-route-sw ...
- Vue学习笔记-Vue.js-2.X 学习(七)===>脚手架Vue-CLI(路由Router)
脚手架Vue-CLI(路由Router) 一 按装(通过新创建脚手架按装),如果在原来的脚手架上按装直接进图型化界面vue ui的插件按装. 二 使用(上面按装下面步骤自动会生成) 第一步:导入路由对 ...
- ASP.NET MVC学习之路由篇(3)
根据路由输出链接 既然是网站开发自然少不了链接,我们已经学会了强大的路由,但是还缺少一步就是能够将这些路由的路径输出到页面,下面我们就开始学习如何输出路由路径. 首先我们的路由注册部分如下所示: 1 ...
随机推荐
- codeforces 578b//"Or" Game// Codeforces Round #320 (Div. 1)
题意:n个数字,最多操作k次,每次乘x,要使结果数组的与值最大. 能推断出结果是对一个元素操作k次,并且这个元素的二进制最高位比较大.并不一定是取最大的,比如1100和1010,乘以一次2,两种选法分 ...
- Confluence 6 从外部目录中同步数据如何工作
下面是有关缓存功能的一些摘要信息: 用户和用户组的缓存信息保存在应用程序的数据库中. 当你连接一个新的外部目录到系统中的时候,一个同步任务将会启动被,并且在后台运行拷贝所有需要的用户和用户组信息,以及 ...
- 快照库MV不能成功刷新问题的解决
前几天,一个用户找到我,说他们的物化视图不能刷新了,这得从几天前主库的一次意外down机说起(另文说明),前几天,用户现场的一个中心库因某原因意外down掉了,当时短期内对中心库进行了重启修复,没有造 ...
- Centos7上部署openstack mitaka配置详解(将疑难点都进行划分)
在配置openstack项目时很多人认为到处是坑,特别是新手,一旦进坑没有人指导,身体将会感觉一次次被掏空,作为菜鸟的我也感同身受,因为已经被掏空n次了. 以下也是我将整个openstack配置过程进 ...
- keras-anomaly-detection 代码分析——本质上就是SAE、LSTM时间序列预测
keras-anomaly-detection Anomaly detection implemented in Keras The source codes of the recurrent, co ...
- Awk 从入门到放弃(1)–学习笔记
参考:朱双印博客 1. 将test文件中的内容打印出来:vmuser@vmuser-virtual-machine:~/panzidong/awk$ echo ddd > testvmuser@ ...
- hadoop redis install (4)
reference: http://dblab.xmu.edu.cn/blog/131/ https://github.com/dmajkic/redis https://blog.csdn ...
- Get gcc built-in macros using command gcc -dM -E - < /dev/null
root@vmuser-virtual-machine:/home/vmuser# gcc -dM -E - < /dev/null #define __SSP_STRONG__ 3#defin ...
- 快速切题 poj2632
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7799 Accepted: 3388 D ...
- 最小生成树之克鲁斯卡尔(Kruskal)算法
学习最小生成树算法之前我们先来了解下 下面这些概念: 树(Tree):如果一个无向连通图中不存在回路,则这种图称为树. 生成树 (Spanning Tree):无向连通图G的一个子图如果是一颗包含G的 ...