stenciljs 学习十三 @stencil/router 组件使用说明
@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 组件使用说明的更多相关文章
- salesforce lightning零基础学习(十三) 自定义Lookup组件(Single & Multiple)
上一篇简单的介绍了自定义的Lookup单选的组件,功能为通过引用组件Attribute传递相关的sObject Name,捕捉用户输入的信息,从而实现搜索的功能. 我们做项目的时候,可能要从多个表中获 ...
- stenciljs 学习七 路由
stenciljs路由类似react router 安装 npm install @stencil/router --save 使用 导入包 import "@stencil/router& ...
- DjangoRestFramework学习三之认证组件、权限组件、频率组件、url注册器、响应器、分页组件
DjangoRestFramework学习三之认证组件.权限组件.频率组件.url注册器.响应器.分页组件 本节目录 一 认证组件 二 权限组件 三 频率组件 四 URL注册器 五 响应器 六 分 ...
- day91 DjangoRestFramework学习三之认证组件、权限组件、频率组件、url注册器、响应器、分页组件
DjangoRestFramework学习三之认证组件.权限组件.频率组件.url注册器.响应器.分页组件 本节目录 一 认证组件 二 权限组件 三 频率组件 四 URL注册器 五 响应器 六 分 ...
- day 89 DjangoRestFramework学习三之认证组件、权限组件、频率组件、url注册器、响应器、分页组件
DjangoRestFramework学习三之认证组件.权限组件.频率组件.url注册器.响应器.分页组件 本节目录 一 认证组件 二 权限组件 三 频率组件 四 URL注册器 五 响应器 六 分 ...
- DjangoRestFramework学习二之序列化组件、视图组件 serializer modelserializer
DjangoRestFramework学习二之序列化组件.视图组件 本节目录 一 序列化组件 二 视图组件 三 xxx 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 序列化组 ...
- day 90 DjangoRestFramework学习二之序列化组件
DjangoRestFramework学习二之序列化组件 本节目录 一 序列化组件 二 xxx 三 xxx 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 序列化组件 首先按照 ...
- Spark学习之基础相关组件(1)
Spark学习之基础相关组件(1) 1. Spark是一个用来实现快速而通用的集群计算的平台. 2. Spark的一个主要特点是能够在内存中进行计算,因而更快. 3. RDD(resilient di ...
- 微信小程序把玩(二十三)modal组件
原文:微信小程序把玩(二十三)modal组件 modal弹出框常用在提示一些信息比如:退出应用,清楚缓存,修改资料提交时一些提示等等. 常用属性: wxml <!--监听button点击事件-- ...
随机推荐
- android--------阿里 AndFix 热修复
AndFix,全称是Android hot-fix.是阿里开源的一个热补丁框架,允许APP在不重新发布版本的情况下修复线上的bug. 支持Android 2.3 到 6.0,并且支持arm 与 X86 ...
- 微信小程序------MD5加密(支持中文和不支持中文)和网络请求(get和post)
开发中常常遇到MD5加密,最近做小程序也用到了,简单总结了一下: 这要有两个加密文件,一个不支持中文,一个支持,所以你选择支持的来用就行了: 也随便说说小程序的get和post网络请求. 来看看效果图 ...
- 50 Jquery 库
一.概念: 1.jquery 的选择器和ccs 相同 2.jquery对象, dom对象的集合,类似python中list,有自己的各种方法和属性 // [dom1,dom2,.....] 3.方便之 ...
- 原生JS和jQuery版实现文件上传功能
<!doctype html> <html lang="zh"> <head> <meta charset="utf-8&quo ...
- form数据请求参数格式
请求后台参数格式问题 当请求后台传递参数时,有多中类型,而每一种都需要前后台进行配合,而这有时候会很简单,有时候却十分困难,记录一下,以备后期深究 数据 后台需要的数据 form表单 嵌套数据,第二层 ...
- POJ 2663 Tri Tiling 矩阵快速幂 难度:3
Tri Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7841 Accepted: 4113 Descri ...
- POJ 3308 Paratroopers 最大流,乘积化和 难度:2
Paratroopers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7267 Accepted: 2194 Desc ...
- jdk1.6中bin目录下的工具及其作用
jdk的javaw.javac等的介绍java:在msdos终端窗口中执行.class文件,即解释执行.class文件.通常所说的jvm解释权.javaw:在java自己的窗口中执行.class文件而 ...
- PHP parse_url 一个好用的函数
array parse_url ( string $url ) 本函数解析一个 URL 并返回一个关联数组,包含在 URL 中出现的各种组成部分. 对严重不合格的 URL,parse_url() 可能 ...
- iOS调用第三方地图App进行导航方法
前言 App内根据手机上装载的地图App将其显示在弹出的选择框,选择对应地图跳转进入地图导航.需要用到- (BOOL)canOpenURL:(NSURL *)url NS_AVAILABLE_IOS( ...