@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. Java基础-String和StringBuilder类型(11)

    String类概述 字符串是由多个字符组成的一串数据字符串可以看成是字符数组 构造方法 public String(String original)public String(char[] value ...

  2. 加密算法(DES,AES,RSA,MD5,SHA1,Base64)比较和项目应用

    加密技术通常分为两大类:"对称式"和"非对称式". 对称性加密算法:对称式加密就是加密和解密使用同一个密钥.信息接收双方都需事先知道密匙和加解密算法且其密匙是相 ...

  3. Andriod给textview文本关键字循环标亮加粗

    在开发中,搜索到得关键字信息在展示时,通常需要标亮加粗,如下图(截取自蓝鲸医生助手搜索后的结果) 在文本中,关键字是“嘎”,所有“嘎”字都标亮加粗,标亮就是换种颜色.这里就要用到SpannableSt ...

  4. POJ 1014 Dividing (多重可行性背包)

    题意 有分别价值为1,2,3,4,5,6的6种物品,输入6个数字,表示相应价值的物品的数量,问一下能不能将物品分成两份,是两份的总价值相等,其中一个物品不能切开,只能分给其中的某一方,当输入六个0是( ...

  5. 正向代理到指定泛域名的nginx配置

    resolver 8.8.8.8; #必须配置!!!不然无法代理 server { listen default_server; listen [::]: default_server; server ...

  6. duilib CEditUI 禁止输入中文字符,禁止复制粘贴

    1.CEditUI 禁止使用中文输入法 在 CEditUI::DoEvent 函数中,添加代码: if(m_bOnlyEnglishChar && m_pWindow &&am ...

  7. js获得焦点和失去焦点那些事

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...

  8. webbrowser 静音(刷新、点击网页的声音)(包括flash静音)

    public enum INTERNETFEATURELIST { FEATURE_OBJECT_CACHING = 0, FEATURE_ZONE_ELEVATION = 1, FEATURE_MI ...

  9. Maven 打jar包,pom文件配置

    以下是pom.xml文件的相关配置. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="h ...

  10. EhLib的行Checkbox

    方法1 http://www.cnblogs.com/jupt/p/4291902.html 在Indicator中添加动态Checkbox,无需绑定数据源,支持全选 - Ehlib学习(二)   先 ...