Comments (5)
可以,这里不适合用重定向,可以考虑下面这种方式
@interceptor(global = true)
public class GlobalInterceptor implements IRouterInterceptor {
public GlobalInterceptor() {
RouterLogger.getAppLogger().d("GlobalInterceptor create");
}
@Override
public void handle(@NonNull final Request request) {
switch (request.getUri().toString()) {
case "/activity/page1":
case "/activity/page2":
DRouter.build("/login")
.start(request.getContext(), new RouterCallback.ActivityCallback() {
@Override
public void onActivityResult(int resultCode, @Nullable Intent data) {
request.getInterceptor().onContinue();
}
});
return;
}
request.getInterceptor().onContinue();
}
}
from drouter.
从activity中跳转是没有问题,但是在fragment 中使用 并不会回调
from drouter.
不会回调是什么意思,怎么使用的?
from drouter.
我在fragment中使用DRouter.build(uri).start()调用路由跳转。
`@Interceptor(
global = true
)
class LoginInterceptor : IRouterInterceptor {
companion object {
const val LOGIN_QUERY = "needLogin"
const val LOGIN_URl = "https://app.ink.net/login"
}
override fun handle(request: Request) {
if (checkNeedLogin(request)) {
DRouter.build(LOGIN_URl)
.start(request.context, object : RouterCallback.ActivityCallback() {
override fun onActivityResult(resultCode: Int, @Nullable data: Intent?) {
Log.d("result,", "${resultCode}")
request.interceptor.onContinue()
}
})
return
} else {
request.interceptor.onContinue()
}
}
private fun checkNeedLogin(request: Request): Boolean {
val needLogin = request.uri.getQueryParameter(LOGIN_QUERY)
if (needLogin.isNullOrEmpty()) {
return false
}
return needLogin.equals("true", false)
}
}`
因为拦截器的原因,所以会进入拦截器。最终也正确在拦截器的作用下进入了登录页,但是我在登录页成功登录以后,并不会执行onActivityResult()方法。
从activity中使用DcRouter.start()就能正常执行
from drouter.
确认一下context是用的Activity吗?代码的设计即便Activity被回收了也会回调回来的,onActivityResult 里 Log.d("result,", "${resultCode}") 这句执行了吗?
抱歉回复晚了,最近业务有调整,后续可以微信直接联系哈
from drouter.
Related Issues (20)
- Support Gradle's configuration cache HOT 1
- io.github.didi:drouter-plugin-proxy id plugin HOT 1
- 能否将Request中的ActivityResultLauncher设置为public? HOT 1
- SHA-256 digest error for org/bouncycastle/asn1/cmc/BodyPartReference.class HOT 5
- Upgrade to gradle 8.0+ HOT 3
- 当使用activityResultLauncher的时候没有看见unregister的调用地方,是否需要手动取消
- 动态模块可以用吗? HOT 1
- javassist 引发的内测泄漏,导致transform临时文件无法被删除 HOT 3
- 如何正确得知路由失败原因 HOT 6
- [Compose] 引入 DRouter 后 Compose 真机预览无法使用 HOT 2
- 页面路由动画 HOT 4
- 偶现编译报错, Output mapping should be non-incremental. HOT 3
- RouterPageStack类,手机物理返回键退栈问题
- 希望能添加自定义的 excludePackage
- dynamic feature模块如何使用?
- 新版依赖插件方式无效,找不到 drouter plugin HOT 1
- XXXDRouterTask产物导致编译时间增加5min+ HOT 1
- 插件扫描遍历时缓存为何不支持windows系统的
- README中图片加载不出来了
- gradle v8版本是不是不支持增量编译?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drouter.