All Projects → michaelxs → Android-XRouter

michaelxs / Android-XRouter

Licence: Apache-2.0 license
This is a lightweight and simple routing framework that provides jump routing and method routing.

Programming Languages

kotlin
9241 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Android-XRouter

Clevergo
👅 CleverGo is a lightweight, feature rich and high performance HTTP router for Go.
Stars: ✭ 246 (+1194.74%)
Mutual labels:  router
lura
Ultra performant API Gateway with middlewares. A project hosted at The Linux Foundation
Stars: ✭ 5,159 (+27052.63%)
Mutual labels:  router
routex.js
🔼 Alternative library to manage dynamic routes in Next.js
Stars: ✭ 38 (+100%)
Mutual labels:  router
rux
⚡ Rux is an simple and fast web framework. support route group, param route binding, middleware, compatible http.Handler interface. 简单且快速的 Go api/web 框架,支持路由分组,路由参数绑定,中间件,兼容 http.Handler 接口
Stars: ✭ 81 (+326.32%)
Mutual labels:  router
svelte-starter-kit
Svelte starter kit — router, state management and testing included.
Stars: ✭ 16 (-15.79%)
Mutual labels:  router
RoundedLayout
This is a library that has a rounded cut of View, support whether the specified corners are cropped and add a custom Border, and add a shadow support from API 9, which is based on FrameLayout, that is, His Child can be any View, the current library or preview version, if you encounter problems in the process can submit issue or pr.
Stars: ✭ 24 (+26.32%)
Mutual labels:  router
Router
Router implementation for fasthttp
Stars: ✭ 234 (+1131.58%)
Mutual labels:  router
Parrot
Web router specially designed for building SPAs using Meteor
Stars: ✭ 75 (+294.74%)
Mutual labels:  router
tulingx
TULINGX(图灵)VPN下载页 翻墙 代理 科学上网 外网 加速器 梯子 路由
Stars: ✭ 59 (+210.53%)
Mutual labels:  router
fast-route
PSR-15 middleware to use FastRoute
Stars: ✭ 91 (+378.95%)
Mutual labels:  router
svelte-micro
Light & reactive one-component router for Svelte
Stars: ✭ 81 (+326.32%)
Mutual labels:  router
dilovel
An advanced framework is written in PHP, a framework containing rich components such as middleware, orm, request management, template engine, elasticsearch, template engine, many modern frameworks have been written by adopting clean code principles completely written in accordance with PHP standards. like linux operating system ...All of control…
Stars: ✭ 38 (+100%)
Mutual labels:  router
easytcp
✨ 🚀 EasyTCP is a light-weight TCP framework written in Go (Golang), built with message router. EasyTCP helps you build a TCP server easily fast and less painful.
Stars: ✭ 416 (+2089.47%)
Mutual labels:  router
Golf
⛳️ The Golf web framework
Stars: ✭ 248 (+1205.26%)
Mutual labels:  router
react-chicane
A simple and safe router for React and TypeScript.
Stars: ✭ 191 (+905.26%)
Mutual labels:  router
Swiftuirouter
Routing in SwiftUI
Stars: ✭ 242 (+1173.68%)
Mutual labels:  router
es6-router
🌐 Simple client side router built in ES6
Stars: ✭ 16 (-15.79%)
Mutual labels:  router
Stime
基于Vue-cli3(Vue+Vue-router)构建的单页单栏Typecho主题,全站Ajax+类Pjax(Vue-router)无刷新,自适应适配移动设备
Stars: ✭ 29 (+52.63%)
Mutual labels:  router
qlevar router
Manage you project Routes. Create nested routes. Simply navigation without context to your pages. Change only one sub widget in your page when navigating to new route.
Stars: ✭ 51 (+168.42%)
Mutual labels:  router
journey
A conductor routing helper library
Stars: ✭ 35 (+84.21%)
Mutual labels:  router

Android-XRouter

[点击查看中文版]

This is a lightweight and simple routing framework that provides jump routing and method routing.

API License

Feature

  • Based on Kotlin
  • Support free assembly of different modules to achieve differential compilation
  • Provide page routing and interceptors
  • Provide method routing including: synchronous and asynchronous
  • Simple and convenient
  • No reflection, high efficiency
  • Super lightweight, less than 42 KB

Setup

1.Add jcenter repository to root's build.gradle

allprojects {
    repositories {
        ...
        jcenter()
    }
}

2.Apply kapt in app's build.gradle and module's build.gradle

...
apply plugin: 'kotlin-kapt'

3.Add dependencies in app's build.gradle and module's build.gradle (please use the latest version)

dependencies {
    ...
    implementation 'com.xuyefeng:xrouter-core:1.1.3'
    kapt 'com.xuyefeng:xrouter-compiler:1.0.6'
}

4.Register routing in app's build.gradle and module's build.gradle

kapt {
    arguments {
        arg("XRouterModule", project.getName())
    }
}

5.Register routing app in app's build.gradle

kapt {
    arguments {
        arg("XRouterApp", project.getName() + ",modulea,moduleb")
    }
}
  • The Routing App consists of three routing modules, app, module, and moduleb. Corresponding to the project name of the route module registered in step 4
  • Here you can dynamically set XRouterApp based on a freely assembled module

6.Initialize XRouter

@RouterApp
class BaseApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        XRouter.init(this, BuildConfig.DEBUG)
    }
}
  • It is recommended to initialize in Application and add annotations @RouterApp
  • In debug mode, you can use XRouter as a tag to filter log information

Usage

Page routing

1.Annotation page (supports one page for multiple routing addresses)

@Router("www.baidu.com")
class MainActivity : AppCompatActivity()

@Router("www.baidu.com", "www.google.com")
class MainActivity : AppCompatActivity()

2.Jump page

// Common jump
XRouter.with(context).target("www.google.com").jump()

// Custom intentFlags
XRouter.with(context)
        .target("www.google.com")
        .intentFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
        .jump()

// Custom jump animation
XRouter.with(context)
        .target("www.google.com")
        .transition(android.R.anim.fade_in, android.R.anim.fade_out)
        .jump()

// Splicing parameters by url
XRouter.with(context)
        .target("www.google.com?name=blue&age=18")
        .jump()

// Passing parameters through the bundle
XRouter.with(context)
        .target("www.google.com")
        .data("name", "blue")
        .data("age", 18)
        .data(Bundle())
        .jump()

// StartActivityForResult
XRouter.with(context)
        .target("www.google.com")
        .requestCode(1001)
        .jump()

// Routing results, only concerned about success
XRouter.with(context)
        .target("www.google.com")
        .jump {
            // jump success to do sth
        }

// Routing results, only concerned with failure
XRouter.with(context)
        .target("www.google.com")
        .jump({
            // jump failure to do sth
        })

// Routing results, including failures and successes
XRouter.with(context)
        .target("www.google.com")
        .jump({
            // jump failure to do sth
        }, {
            // jump success to do sth
        })

3.Interceptor

@RouterInterceptor(priority = 8)
public class LoginInterceptor implements XRouterInterceptor {
    @Override
    public void onInit(@NotNull Context context) {
        // do something in application init
    }
    @Override
    public void onProcess(@NotNull XRouterInterceptorCallback callback) {
        // check login status
      	...
      	// check success
        callback.onContinue();
        // or check failure
        callback.onIntercept("check login error");
    }
}
  • The parameter priority determines the priority of the interceptor. The default is 5. The higher the value, the higher the priority
  • Multiple interceptors can be defined, executed sequentially according to priority
  • The onInit method is called when the XRouter is initialized and can be used for interceptor initialization
  • The onProcess method is called in the page route and can be used for page blocking. The classic scenario is that the login status needs to be detected during the page routing process. If the login status is invalid, the original route is terminated and changed to jump to the login interface

Method routing

1.Annotation method

@Router("toast")
fun toast(context: Context, routerParams: XRouterParams): XRouterResult {
    Toast.makeText(context, "toast from other module", Toast.LENGTH_SHORT).show()
    return XRouterResult.Builder().build()
}

@Router("getSum", async = true)
fun getSum(context: Context, routerParams: XRouterParams, callback: XRouterCallback?) {
    // get object data
    val fragment = routerParams.obj as Fragment
    // get data
    val a = routerParams.data.getInt("a")
    val b = routerParams.data.getInt("b")
    ...
    val sum = a + b
    val result = XRouterResult.Builder().data("sum", sum).obj(fragment).build()
    callback?.onRouterSuccess(result)
    // or
    callback?.onRouterError(result)
}
  • Annotated methods need to be global static methods
  • The name of the annotation can be different from the method name, the name of the annotation is used to find the target method, and the method name is used to execute the method
  • The default is synchronous routing. You can enable asynchronous routing through the annotation parameter async
  • The parameters received by all synchronous routes are Context and XRouterParams. Please keep the same way
  • The parameters received by all asynchronous routes are Context, XRouterParams, and XRouterCallback. Please keep the same syntax
  • The parameters passed by the route can be obtained through XRouterParams. The parameters of the route result can be set by XRouterResult. Both pass the parameters by bundle, and obj passes the object data

2.Call method

// No-parameter routing
XRouter.with(context).target("toast").route()

// Passing parameters through the bundle
XRouter.with(context)
        .target("doSomething")
        .data("name", "blue")
        .data("age", 18)
        .route()

// Object passing
XRouter.with(context)
        .target("doSomething")
        .obj(Fragment())
        .route()

// Synchronous route acquisition result
val result = XRouter.with(context)
        .target("getSum")
        .data("a", 1)
        .data("b", 2)
        .route()

// Asynchronous routing gets results, only concerned about success
XRouter.with(context)
        .target("getSum")
        .data("a", 1)
        .data("b", 2)
        .route {
            // get params
            val sum = it.getData().getInt("sum")
            val fragment = it.getObj() as Fragment
            // route success to do sth
        }

// Asynchronous routing gets results, only cares about failure
XRouter.with(context)
        .target("getSum")
        .data("a", 1)
        .data("b", 2)
        .route ({
            // route failure to do sth
        })

// Asynchronous route gets the result, including failure and success
XRouter.with(context)
        .target("getSum")
        .data("a", 1)
        .data("b", 2)
        .route ({
            // route failure to do sth
        },{
            // get params
            val sum = it.getData().getInt("sum")
            val fragment = it.getObj() as Fragment
            // route success to do sth
        })

ProGuard

-keep class com.blue.xrouter.** {*;}
-keep interface com.blue.xrouter.** {*;}

License

Apache-2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].