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 学习七 路由的更多相关文章

  1. MyBatis学习七:spring和MyBatis整合

    <\mybatis\day02\16mybatis和spring整合-sqlSessionFactory配置.avi;> MyBatis学习七:spring和MyBatis整合.逆向工程 ...

  2. SVG 学习<七> SVG的路径——path(1)直线命令、弧线命令

    目录 SVG 学习<一>基础图形及线段 SVG 学习<二>进阶 SVG世界,视野,视窗 stroke属性 svg分组 SVG 学习<三>渐变 SVG 学习<四 ...

  3. day 85 Vue学习七之vue-cookie

      Vue学习七之vue-cookie   通过vue如何操作cookie呢 参考链接:https://www.jianshu.com/p/535b53989b39 第一步:安装vue-cookies ...

  4. (转)MyBatis框架的学习(七)——MyBatis逆向工程自动生成代码

    http://blog.csdn.net/yerenyuan_pku/article/details/71909325 什么是逆向工程 MyBatis的一个主要的特点就是需要程序员自己编写sql,那么 ...

  5. Django学习之路由分发和反向解析

    原 Django学习之路由分发和反向解析 2018年07月12日 14:04:55 huangql517 阅读数 519 1>路由分发 我们之前学习的路由配置都是在项目的全局控制文件(项目名称目 ...

  6. nodejs学习笔记<七> 路由

    // 引用模块(与C#中命名空间,Java中引用包同理) var http = require("http"); var path = require("path&quo ...

  7. stenciljs 学习十二 官方doc 路由使用的例子

    路由在单页面应用开发中是一个相对比较重要的位置 以下为官方网站的路由配置 <stencil-router scrollTopOffset={0}> <stencil-route-sw ...

  8. Vue学习笔记-Vue.js-2.X 学习(七)===>脚手架Vue-CLI(路由Router)

    脚手架Vue-CLI(路由Router) 一 按装(通过新创建脚手架按装),如果在原来的脚手架上按装直接进图型化界面vue ui的插件按装. 二 使用(上面按装下面步骤自动会生成) 第一步:导入路由对 ...

  9. ASP.NET MVC学习之路由篇(3)

    根据路由输出链接 既然是网站开发自然少不了链接,我们已经学会了强大的路由,但是还缺少一步就是能够将这些路由的路径输出到页面,下面我们就开始学习如何输出路由路径. 首先我们的路由注册部分如下所示: 1 ...

随机推荐

  1. oracle使用(1)

    纯粹是记录工作中使用的分析函数或是语法点,不做其他用处. (1) with as 先举个例子吧: 有两张表,分别为A.B,求得一个字段的值先在表A中寻找,如果A表中存在数据,则输出A表的值:如果A表中 ...

  2. Ant Man CodeForces - 704B (图论,贪心)

    大意: 给N个点,起点S终点T,每个点有X,A,B,C,D,根据I和J的X坐标可得I到J的距离计算公式 |xi - xj| + ci + bj seconds if j< i |xi - xj| ...

  3. Ubuntu18.04配置静态ip遇到的报错

    说明: 因为很多测试环境在这个Ubuntu系统上装着,却由于虚拟服务器的重启.断电,每次Ip发生变化,就得更新环境,所以需要把该环境的ip配置成静态的,一劳永逸. 根据以往配置Ubuntu静态ip的经 ...

  4. protobuf3.5.1使用的简单例子

    前言 1. 什么是protobuf Google Protocol Buffer( 简称 Protobuf) 是 Google 公司内部的混合语言数据标准,是一种轻便高效的结构化数据存储格式,平台无关 ...

  5. spark shuffle内在原理说明

    在MapReduce框架中,shuffle是连接Map和Reduce之间的桥梁,Map的输出要用到Reduce中必须经过shuffle这个环节,shuffle的性能高低直接影响了整个程序的性能和吞吐量 ...

  6. 在Ubuntu系统下设置永久性Swap交换空间(转帖)

    http://blog.sina.com.cn/s/blog_6e4388910100tsk7.html swap 一般都在一个专有的swap区里,这可能是因为在安装的时候系统会提示你创建一个swap ...

  7. 微信小程序中的bindTap事件(微信小程序开发QQ群:604788754)

    bindTap对应的绑定事件, 第一个:wx.navigateTo wx.navigateTo({ url:"../content/content" }) 第二个:wx.redir ...

  8. hadoop mongodb install(3)

    reference:http://dblab.xmu.edu.cn/blog/868-2/ root@iZuf68496ttdogcxs22w6sZ:~# mv mongodb-linux-x86_6 ...

  9. 51nod1671

    题解: 这一题感觉和noip2015d2t3一模一样,而且是弱化版 但是,后来发现貌似每两个点都可以建立虫洞 好在是i和i+1有边,所以就直接用二分+贪心了 代码: #include<bits/ ...

  10. AsyncTask 异步任务 的用法(并且使用ORMlite关系数据库);

    package com.lixu.asynctask; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.tab ...