All Projects → esafirm → universal-router

esafirm / universal-router

Licence: MIT License
↩️ Router for every occasions

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to universal-router

Lotusoot
灵活的 Swift 组件解耦和通信工具
Stars: ✭ 324 (+406.25%)
Mutual labels:  modular, router
Http
An opinionated framework for scalable web 🌎
Stars: ✭ 136 (+112.5%)
Mutual labels:  modular, router
Zikrouter
Interface-oriented router for discovering modules, and injecting dependencies with protocol in Objective-C and Swift.
Stars: ✭ 516 (+706.25%)
Mutual labels:  modular, router
Marshroute
Marshroute is an iOS Library for making your Routers simple but extremely powerful
Stars: ✭ 208 (+225%)
Mutual labels:  router, navigation
Helm
A graph-based SwiftUI router
Stars: ✭ 64 (+0%)
Mutual labels:  router, navigation
Swiftuirouter
Routing in SwiftUI
Stars: ✭ 242 (+278.13%)
Mutual labels:  router, navigation
Navigator
Android Multi-module navigator, trying to find a way to navigate into a modularized android project
Stars: ✭ 131 (+104.69%)
Mutual labels:  modular, navigation
Redux Saga Router
A router for Redux Saga
Stars: ✭ 153 (+139.06%)
Mutual labels:  router, navigation
Parrot
Web router specially designed for building SPAs using Meteor
Stars: ✭ 75 (+17.19%)
Mutual labels:  router, navigation
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 (-20.31%)
Mutual labels:  router, navigation
Android Router
An android componentization protocol framework, used for decoupling complex project. Android高性能轻量级路由框架
Stars: ✭ 208 (+225%)
Mutual labels:  router, navigation
go router
The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
Stars: ✭ 380 (+493.75%)
Mutual labels:  router, navigation
Arouter
💪 A framework for assisting in the renovation of Android componentization (帮助 Android App 进行组件化改造的路由框架)
Stars: ✭ 13,587 (+21129.69%)
Mutual labels:  router, navigation
RouterService
💉Type-safe Navigation/Dependency Injection Framework for Swift
Stars: ✭ 212 (+231.25%)
Mutual labels:  modular, navigation
React Router Native Stack
A stack navigation component for react-router-native
Stars: ✭ 171 (+167.19%)
Mutual labels:  router, navigation
Tinypart
TinyPart is an iOS modularization framework implemented by Ojective-C. It also supports URL-routing and inter-module communication. TinyPart是一个由Objective-C编写的面向协议的iOS模块化框架,同时它还支持URL路由和模块间通信机制。
Stars: ✭ 120 (+87.5%)
Mutual labels:  modular, router
Corenavigation
📱📲 Navigate between view controllers with ease. 💫 🔜 More stable version (written in Swift 5) coming soon.
Stars: ✭ 69 (+7.81%)
Mutual labels:  router, navigation
Hookrouter
The flexible, and fast router for react that is entirely based on hooks
Stars: ✭ 1,200 (+1775%)
Mutual labels:  router, navigation
NavigationRouter
A router implementation designed for complex modular apps, written in Swift
Stars: ✭ 89 (+39.06%)
Mutual labels:  modular, navigation
navigation-skeleton
This component allows you to show skeletons of pages during navigation process.
Stars: ✭ 16 (-75%)
Mutual labels:  router, navigation

Universal Router

Router for every ocassion ~

Universal router comes with two flavor, the core module which basically a link router that can convert your URI to whatever you need. And the Android module which more opinionated to how you can use it to help you solve your navigation problem

Download

Add this to your project build.gradle

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

And add this to your module build.gradle

dependencies {
    implementation "com.github.esafirm.universal-router:core:$routerVersion"
    implementation "com.github.esafirm.universal-router:android:$routerVersion"
}

Core

It basically consist of two router

  1. SimpleRouter which route Any type of object to anything you need
  2. UrlRouter which takes URI instead of object

Some Examples

// Define router
class StringRouter : UrlRouter<String>() {

    init {
        addEntry("nolambda://test/{a}/{b}", "https://test/{a}/{b}") { _, param ->
            val first = param["a"]
            val second = param["b"]
            "$second came to the wrong neighborhood $first"
        }
    }
}

// Call router
// This will return string "you can to the wrong neighborhood yo"
StringRouter().resolve("nolambda://test/yo/you")

For more sample, plese look at the samples directory.

Android

Basically with just the core module you already can have a navigation system in your modular structured application (think dynamic module use case). The easiest way would be creating a Singleton router in your "core" module and then add entries in every other module, but this can get quite messy sometimes, this is when the android router module comes in.

First let's define our project structure:

project
│
├── app // Android app module, depends to all modules
│
├── cart // Feature cart, only depends to router
│
├── product // Feature product, only depends to router
│
└── approuter // Router libs that every module depends

In dynamic module use case the cart and product module would be depends the app module

Next what you want to create is the list of the routes in the "router" module, in this case approuter

object AppRouter {
    // Simplest form of Route
    object Home : Route()
    // Route support deeplink navigation
    object Cart : Route("https://bukatoko.com/cart")
    // Route also support navigation with parameter
    object Product : RouteWithParam<Product.ProductParam>(
        paths = arrayOf("https://bukatoko.com/{product_id}", "app://product/{id}"),
    ) {
        data class ProductParam(
            val productId: String
        )
    }
}

After that, you have to register your navigation logic to the Route

AppRouter.Cart.Register {
    context.startActivity(Intent(context, CartScreen::class.java))
}

If you want to initiate this in startup and your module doesn't have the access to Application class you can use the initializer

class CartRouterInitializer : RouterInitializer {
    override fun onInit(appContext: Context) {
        ... // do as above
    }
}

Don't forget to register this on manifest

<provider
    android:name=".CartRouterInitializer"
    android:authorities="nolambda.router.cart"
/>

This is actually it if your navigation logic nature is "fire and forget", but in case you have to get something back (like Fragment) and use it in other place you can use the RouteProcessor<T>

// Processor only process return that has the same type as passed class
// In this case it will only process router that return Fragment
Router.addProcessor<Fragment> {
    supportManager.beginTransaction()
        .replace(R.id.container, it)
        .commit()
}

After that you can use the Router to navigate your app

// This will trigger Cart register lambda
Router.push(AppRouter.Cart)

// You can use the registered deeplink too
Router.goTo("https://bukatoko.com/cart")

And that's it you got yourself a navigation system.

I can't stress enough that you should check samples for better understanding of the library

What's Next

  • Navigation type (push, replace, pop)
  • Annotation auto register (It's partially working now) �

License

MIT @ Esa Firman

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].