Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

分享一个router的实际使用场景 #32

Closed
zhangchaoxu opened this issue Jun 8, 2017 · 1 comment
Closed

分享一个router的实际使用场景 #32

zhangchaoxu opened this issue Jun 8, 2017 · 1 comment

Comments

@zhangchaoxu
Copy link

zhangchaoxu commented Jun 8, 2017

如图,这是最近完成的一个app的首页。
default

首页提供有许多的功能入口,而且功能(包括图片、文字、跳转页面)都是会变化的。
解决的思路是是包括banner、grid、marquee都是通过接口获取配置文件,同时将配置文件缓存在本地。
启动的时候先加载本地缓存配置文件,然后通过接口对比本地配置文件的版本和线上版本,有更新则替换缓存同时刷新页面。

配置文件属性主要包括title、img、path、loginRequired,分别用于来控制显示的标题、图片、跳转页面以及跳转页面是否必须要先登录。

path

对于Router.build(path)。定义有三种类型

  1. 空 则表示不跳转、功能暂时未实现、点击无对于事件等情况
  2. ADView这样的标记,表示需要在app中实现的功能
  3. http开始的链接
    3.1 app中已实现的功能。比如http://example.com/h5/ad/view?id=123。 可能app中已经实现了一个ADView.activity。则给这个ADViewActivity.java加上了@Route({"ADView", "http://example.com/h5/ad/view"})注解。由于android、ios进度差异、各版本之间差异等情况,有些app中未实现这个ADView的原生功能,这个时候就是直接打开这个ad/view?id=123的h5链接。
    3.2 app中未实现或者不准备实现的功能,直接用浏览器打开这个path地址就可以。至于如何用app自己实现的浏览器来打开可以参见help wanted: 如何自定义BrowserMatcher处理流程 #30

loginRequired

有些功能是需要登录的,有些功能可以不需要,这个时候可以通过loginRequired在跳转之间做判断,也可以在被跳转页面通过注解跳转,比如上面提到的ADViewActivity查看功能,是一个登录用户才可以使用的功能,这个时候就可以在ADViewActivity中加上LoginInterceptor

@chenenyu
Copy link
Owner

chenenyu commented Jun 9, 2017

完全发挥了Router的优势,感谢分享,app做的很赞 👍 如果还有其他功能性的需求,欢迎反馈 😆

@chenenyu chenenyu pinned this issue Jan 23, 2019
@chenenyu chenenyu unpinned this issue Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants