美文网首页
Arouter IInterceptor拦截器使用

Arouter IInterceptor拦截器使用

作者: 咚咚_Coding | 来源:发表于2021-07-25 23:27 被阅读0次
跳详情页强校验登陆
App大了之后会有多种跳转方式,比如短链、web、app内、push等,想在跳转前做一些事情,那么拦截器就派上用场了

@Interceptor(priority = 10, name = "详情页校验登陆状态")
public class DetailInterceptor implements IInterceptor {

private Context mContext;

@Override
public void process(Postcard postcard, InterceptorCallback callback) {
    try {
        //未登陆&是详情  那么登陆并跳转
        if (!LoginManager.isLogin() && postcard.getPath().equals(SyRouter.DETAILS) && null != postcard.getUri()) {
          //跳转登陆页面吧.....
            return;
        }
        //正常跳转....
        callback.onContinue(postcard);
    } catch (Exception e) {
        e.printStackTrace();
        callback.onContinue(postcard);
    }

}

@Override
public void init(Context context) {
    this.mContext = context;
}
}

相关文章

网友评论

      本文标题:Arouter IInterceptor拦截器使用

      本文链接:https://www.haomeiwen.com/subject/qyjrmltx.html