stenciljs路由类似react router

安装

  1. npm install @stencil/router --save

使用

  1. 导入包
  2. import "@stencil/router"
  3. 添加路由组件配置

包含的组件

  • stencil-router
    项目中应该只有一个模板路由器组件。此组件控制与浏览器历史记录的所有交互,
    并通过事件系统聚合更新
  • stencil-route
    此组件基于提供的URL是否与当前位置匹配来呈现。
    包含的属性
  1. url (Array||string) 同时可以传递参数 /foo/:bar
  2. component (string) 组件名称
  3. componentProps (组件的属性)包含传递给组件渲染的数据
  4. routeRender function 接受属性作为参数的函数。如果存在,则将使用它来代替定义的组件
  5. exact boolean 如果为true,则只有当url与该地址完全匹配时才呈现此路由,如果为false,则在当前url'匹配'定义的url时呈现
  • stencil-route-link
    此组件用于渲染指向已定义路由的链接。可以与当前地址是否匹配应用特定样式。
    包含的属性
  1. url (string) 连接的路径
  2. exact (boolean) 如果为true,则只有当url与该地址完全匹配时才应用activeclass
  3. activeClass string 匹配时候应用的css效果
  • stencil-route-redirect
    url 地址重定向

配置路由

  1. <stencil-router>
  2. <stencil-route url="/" component="landing-page" exact={true}/>
  3. <stencil-route url="/demos" component="demos-page"/>
  4. <stencil-route url="/demos/rendering" component="fiber-demo"/>
  5. <stencil-route url="/docs" component="docs"/>
  6. <stencil-route url="/docs/getting-started" component="getting-started"/>
  7. <stencil-route url="/components" component="basics-components"/>
  8. </stencil-router>

导航

  • 静态导航
    使用 stencil-route-link
  1. <stencil-route-link url="/">
  2. <stencil-route-link url="/demos">
  3. <stencil-route-link url="/docs/getting-started">
  • 编程方式
    import 操作方法
  1. import { RouterHistory } from '@stencil/router';
  2. export class askPage {
  3. @Prop() history: RouterHistory;
  4. }

包含的方法

  1. // pushing a route (going forwards to a certain route)
  2. this.history.push(`/demos`, {});
  3. // navigate back as if the user hit the back button in the browser
  4. this.history.goBack();
  5. // navigate forwards as if the user hit the forwards button in the browser
  6. this.history.goForward();
  7. // replace the current nav history and reset to a certain route
  8. this.history.replace('/', {});
  9. // navigate through the history stack by `n` entries
  10. this.history.go(n: number);

url 参数

  • 传递的方式
  1. <stencil-route url='/show/:pageNum' component='show-page' />
  2. <stencil-route-link url={`/show/${someData}`} />
  • 组件获取参数
  1. import { MatchResults } from '@stencil/router';
  2. ...
  3. export class ShowPage {
  4. @Prop() match: MatchResults;
  5. }
  6. 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. Android控件Gridview实现多个menu模块,可添加可删除

    此案例主要讲的是Android控件Gridview(九宫格)完美实现仿支付宝首页,包含添加和删除功能:Fragment底部按钮切换的效果,包含四个模块,登录页面圆形头像等,一个小项目的初始布局. 效果 ...

  2. jenkins X 和k8s CI/CD

    架构 二.核心组件 1.包管理工具     1.1.helm工具包    https://github.com/helm/helm      1.2.Chartmuseum开源helm chart仓库 ...

  3. UVA-10318 Security Panel (DFS+剪枝)

    题目大意:求将一个r*c的按钮矩阵由全部为关变成全部为开的最少按扭次数,每按一次开关能作用到的范围不定. 题目分析:开关问题.打眼一看就是BFS+位压缩,但是写出来之后TLE.用DFS不断更新最优解. ...

  4. HDOJ1003

    #include<iostream> using namespace std; int main() { ],t=,m; cin >> n; while(n--) { cin ...

  5. OC 继承

    一.基本概念 程序的世界和人类的“对象”世界在思想上是没有设么区别的,富二代继承了父母,自然就拥有了父母拥有的所有资源,子类继承了父类同样就拥有了父类所有的方法和属性(成员变量). 在这里动物是猫类和 ...

  6. bzoj2014

    题解: 按照单价排序 然后贪心 代码: #include<bits/stdc++.h> using namespace std; ; typedef long long ll; ll an ...

  7. String比较相等的问题探索

    String比较相等的问题探索 工作上,有个同事犯了个低级错误,把字符串的计较用了==.由于代码已经交付客户,上了生产环境,给公司带了了损失.于是看了他的代码,自己根据以前学的知识,写了几个小demo ...

  8. ShellExecute函数的问题

    情境:自己写了一个loading画面,定时器到时间后调用shellexecute函数调用真正的程序. 问题:调用时出错,说找不到dll资源,但是用鼠标双击确可以打开. 经过分析之后,应该是路径的问题, ...

  9. flashfxp 命令行

    以后更新软件时,尽量用bat命令行 http://www.flashfxp.com/forum/flashfxp/frequently-asked-questions-faq-/14748-comma ...

  10. WordCount:C语言实现

    项目地址:https://github.com/m8705/WordCount 项目要求 wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数. 这个项目要求写一个命令行程序,模仿已 ...