@stencil/router 组件包含的子组件

  • stencil-router
  • stencil-route-switch
  • stencil-route
  • stencil-route-link
  • stencil-route-redirect
  • stencil-route-title

stencil-router 说明

参数:
root 根路径路由处理的为位置
historyType history 类型 browser 或者hash
titlesuffix 页面title 的后缀,可以通过routetitle 更新
参考格式:

<stencil-router titleSuffix=" - My App">
<stencil-route-switch scrollTopOffset={0}>
<stencil-route url="/" component="landing-page" exact={true} />
<stencil-route url="/demos" component="demos-page" />
<stencil-route url="/other" component="other-page" />
<stencil-route component="page-not-found" />
</stencil-route-switch>
</stencil-router>

stencil-route-switch

参考格式:

<stencil-router>
<stencil-route-switch scrollTopOffset={0}>
<stencil-route url="/" component="landing-page" exact={true}/>
<stencil-route url="/demos" component="demos-page" />
<stencil-route component="catch-all" />
</stencil-route-switch>
</stencil-router>

用户认证路由配置

使用了一个routerender 并定义自定义配置
参考

const PrivateRoute = ({ component, ...props}: { [key: string]: any}) => {
const Component = component;
const redirectUrl = props.failureRedirect | '/login';
return (
<stencil-route {...props} routeRender={
(props: { [key: string]: any}) => {
if (auth.isAuthenticated) {
return <Component {...props} {...props.componentProps}></Component>;
}
return <stencil-router-redirect url="/login"></stencil-router-redirect>
}
}/>
);
}
auth
const auth = {
isAuthenticated: false,
authenticate: function() {
this.isAuthenticated = true;
},
logout: function() {
this.isAuthenticated = false;
}
}
const isAuthenticated = (): boolean => {
return isUserLoggedIn;
}

配置router

<stencil-router titleSuffix="My App - ">
<stencil-route-switch scrollTopOffset={0}>
<stencil-route url="/" component="landing-page" exact={true} />
<PrivateRoute url="/user" component="user-info" />
<PrivateRoute url="/org" component="org-info" />
</stencil-route-switch>
</stencil-router>

stencil-route 配置每条路由

  • 基本配置
 <stencil-route url="/" component="landing-page" exact={true} />
  • 多路径配置
  <stencil-route url={["/", "home"]} component="landing-page" exact={true} />
  • 路由参数
  <stencil-route url="/page/:pageNum(\\d+)" component="page-item" />
<stencil-route url="/user/:name?" component="user-page" />
<stencil-route url="/user*" component="user-page" />
  • 组件属性传递
  <stencil-route url="/" component="landing-page"
componentProps={{ firstName: 'Ellie' }} />
  • 配置routerender函数
<stencil-route url="/" exact={true} routeRender={
(props: { [key: string]: any}) => {
return <span>Hello {props.firstName}</span>;
}
} />

stencil-route-link 配置

  • 基本配置
    可以配置连接的地址,样式
  <stencil-route-link url="/" exact={true}>Home</stencil-route-link>
<stencil-route-link url="/info" urlMatch="/info/*">Information</stencil-route-link>
<stencil-route-link url="/info" activeClass="link-active">
Information
</stencil-route-link>
  • 锚属性配置
  <stencil-route-link
url="/"
anchorClass="site-link"
anchorRole="link"
anchorTitle="Home link"
anchorTabIndex="2"
>
Home
</stencil-route-link>

stencil-route-redirect 配置重定向

就一个参数url
参考:

  <stencil-route-redirect url="/" />

stencil-route-title

更新页面的title,主要参数title

  <stencil-route-title title="Home" />

not found 路由配置

可以方便的使用stencil-route-switch 处理

<stencil-router>
<stencil-route-switch scrollTopOffset={0}>
<stencil-route url="/" component="landing-page" exact={true}/>
<stencil-route url="/demos" component="demos-page" />
<stencil-route component="catch-all" />
</stencil-route-switch>
</stencil-router>

编程使用

  • 导入方法
import { RouterHistory } from '@stencil/router';

export class askPage {
@Prop() history: RouterHistory;
}
  • 基本方法
// pushing a route (going forwards to a certain route)
this.history.push(`/demos`, {}); // popping a route (going back to a certain route)
this.history.pop('/home', {}); // 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);

参考资料

https://github.com/ionic-team/stencil-router/wiki

 
 
 
 

stenciljs 学习十三 @stencil/router 组件使用说明的更多相关文章

  1. salesforce lightning零基础学习(十三) 自定义Lookup组件(Single & Multiple)

    上一篇简单的介绍了自定义的Lookup单选的组件,功能为通过引用组件Attribute传递相关的sObject Name,捕捉用户输入的信息,从而实现搜索的功能. 我们做项目的时候,可能要从多个表中获 ...

  2. stenciljs 学习七 路由

    stenciljs路由类似react router 安装 npm install @stencil/router --save 使用 导入包 import "@stencil/router& ...

  3. DjangoRestFramework学习三之认证组件、权限组件、频率组件、url注册器、响应器、分页组件

    DjangoRestFramework学习三之认证组件.权限组件.频率组件.url注册器.响应器.分页组件   本节目录 一 认证组件 二 权限组件 三 频率组件 四 URL注册器 五 响应器 六 分 ...

  4. day91 DjangoRestFramework学习三之认证组件、权限组件、频率组件、url注册器、响应器、分页组件

    DjangoRestFramework学习三之认证组件.权限组件.频率组件.url注册器.响应器.分页组件   本节目录 一 认证组件 二 权限组件 三 频率组件 四 URL注册器 五 响应器 六 分 ...

  5. day 89 DjangoRestFramework学习三之认证组件、权限组件、频率组件、url注册器、响应器、分页组件

    DjangoRestFramework学习三之认证组件.权限组件.频率组件.url注册器.响应器.分页组件   本节目录 一 认证组件 二 权限组件 三 频率组件 四 URL注册器 五 响应器 六 分 ...

  6. DjangoRestFramework学习二之序列化组件、视图组件 serializer modelserializer

      DjangoRestFramework学习二之序列化组件.视图组件   本节目录 一 序列化组件 二 视图组件 三 xxx 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 序列化组 ...

  7. day 90 DjangoRestFramework学习二之序列化组件

      DjangoRestFramework学习二之序列化组件   本节目录 一 序列化组件 二 xxx 三 xxx 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 序列化组件 首先按照 ...

  8. Spark学习之基础相关组件(1)

    Spark学习之基础相关组件(1) 1. Spark是一个用来实现快速而通用的集群计算的平台. 2. Spark的一个主要特点是能够在内存中进行计算,因而更快. 3. RDD(resilient di ...

  9. 微信小程序把玩(二十三)modal组件

    原文:微信小程序把玩(二十三)modal组件 modal弹出框常用在提示一些信息比如:退出应用,清楚缓存,修改资料提交时一些提示等等. 常用属性: wxml <!--监听button点击事件-- ...

随机推荐

  1. synchronized同步代码块锁释放

    今天发现自己写的线上程序出现数据库不能同步的问题,查看日志已经停止记录,随后使用jstack查看线程的运行状况,发现有个同步线程锁住了. 以下是jstack -l 637  问题线程的内容. &quo ...

  2. 转 解决linux下tomcat的shutdown命令杀不死进程

    tomcat在windows下可以直接关闭,但是貌似在Linux下有时候shutdown.sh 没有关闭tomcat进程; 现象:在Linux下shutdown.sh ,然后查看tomcat进程发现没 ...

  3. python-day67--MTV之Template

    一.什么是模板? html+模板语法 二.模版包括在使用时会被值替换掉的 变量,和控制模版逻辑的 标签. 三.嵌入变量的三种方式: def current_time(req): # ========= ...

  4. OAF在打开的新页面中添加按钮,功能是关闭当前页面

    OAF在打开的新页面中添加按钮,功能是关闭当前页面 javascript:close()

  5. oracle进行字符串拆分并组成数组

    CREATE OR REPLACE TYPE CUX_STR_SPLIT_TYPE IS TABLE OF VARCHAR2 (4000); CREATE OR REPLACE PACKAGE cux ...

  6. Nginx 关于 location 的匹配规则详解

    有些童鞋的误区 1. location 的匹配顺序是“先匹配正则,再匹配普通”. 矫正: location 的匹配顺序其实是“先匹配普通,再匹配正则”.我这么说,大家一定会反驳我,因为按“先匹配普通, ...

  7. @RunWith和 SpringJUnit4ClassRunner ---->junit4和Spring一起使用

    今天在看Spring的Demo的时候,看到了如此单元测试的写法 如下: @RunWIth(SpringJunit4ClassRunner.class) @ContextConfiguration(lo ...

  8. Mac OS X 10.9下解决cocos2d-x在Xcode4.6.x的模板不显示问题

    最近将iMac 升级到10.9了,奇怪的事情发生了,cocos2d-x的模板不见了,鼓捣了半天发现问题所在 打开xcode新建工程却找不到cocos2d-x的模板. 经过在网上的苦苦搜寻和试验后,找到 ...

  9. sping整合redis,以及做mybatis的第三方缓存

    一.spring整合redis Redis作为一个时下非常流行的NOSQL语言,不学一下有点过意不去. 背景:学习Redis用到的框架是maven+spring+mybatis(框架如何搭建这边就不叙 ...

  10. AFNetworking 遇到错误 Code=-1016 "Request failed: unacceptable content-type: text/plain"

    在开发过程使用了AFNetworking库,版本2.x,先运行第一个官方例子(替换GET 后面的url即可): AFHTTPRequestOperationManager *manager = [AF ...