Crossroad icon indicating copy to clipboard operation
Crossroad copied to clipboard

registering a route with a path, the scheme is redundant

Open aelam opened this issue 4 years ago • 9 comments

https://github.com/giginet/Crossroad/blob/4788906925bba46eb5623ade4cd320b8526052d3/Tests/CrossroadTests/RouterTests.swift#L38-L60

When we register it's such a trouble to write the scheme all the time when we've declared the scheme for Router! If you really wan to do so, you should let the same router supports both scheme and http url too!

L53~L58 should be true

considering the http url, that's a pain for registering too

aelam avatar Feb 18 '21 05:02 aelam

Thanks for your feedback! I have an idea. I'll implement multiple schemes support soon.

giginet avatar Feb 20 '21 10:02 giginet

Thanks for your reply!

For the registeration, I think I misunderstand it, the url doesn't require a scheme when configuring which is great.

Considerable points:

  1. Multiple urls for same handler
  2. a router can be configured with both scheme and URL. for the registeration just focus on the path

And I'm thinking if there is a globalRouter could be better? Coz the instance of router is only available in the SAME space. I can't use the router in a separated module which could be intergrated in app later.

Thank you

Kohki Miki [email protected] 于 2021年2月20日周六 19:29写道:

Thanks for your feedback! I have an idea. I'll implement multiple schemes support soon.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/giginet/Crossroad/issues/31#issuecomment-782602468, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABYXELR2KY6XOQ47AICIG3S76FHZANCNFSM4XZUUWCA .

aelam avatar Feb 20 '21 11:02 aelam

there should be like a globalRouter singletom, when people register routes in routers, the routers should be loaded in globalRouters then users can just use globalRouter for routing

aelam avatar Feb 22 '21 02:02 aelam

I don't agree Crossroad should provide a global router. I think libraries should keep avoiding global states as we can.

I expect that AppDelegate has a router and register all routes into that in most use cases. If you need a global router, you're better to prepare static variables in each apps.

giginet avatar Feb 22 '21 03:02 giginet

Image you get 4 modules, A B C D, you don't want A depends on B, but A use a route page1OfB How do you use the router in modules AppDelegate is not available in any module. supposed the modules are managed by CocoaPods or SwiftPM the globalRouter should be fully configured by users.

Your case is that everything is in a same project. But image there are 100 modules managed by CocoaPods in your project

aelam avatar Feb 22 '21 03:02 aelam

Multimodule structures are varied by each project. (how to resolve dependencies between each module, abstraction way, etc...)

So I think Crossroad should not provide global routers. You're better to implement a simple wrapper of Crossroad.Router and share that among whole modules if you need.

By the way, this issue discusses multiple URL scheme support. So if you need more discussion about a global router. Could you make another issue?

giginet avatar Feb 22 '21 04:02 giginet

@aelam I tried to implement this feature. However, DSL would be very complex. So it needs radical changes for inner implementations.

First, I'm planning to support multiple schemes( or URLs) for one router. After the changes, I'll work supporting multiple routes for one handler.

Please moment.

giginet avatar Mar 02 '21 07:03 giginet

@aelam I apologize to keep you waiting.

I released 4.0.0.

Crossroad 4.0.0 supports grouped routes. https://github.com/giginet/Crossroad/tree/9b004cd661b8058657623bced487d6085e1ca925#multiple-link-sources-support

let customURLScheme: LinkSource = .customURLScheme("pokedex")
let pokedexWeb: LinkSource = .universalLink(URL(string: "https://my-awesome-pokedex.com")!)
let anotherWeb: LinkSource = .universalLink(URL(string: "https://kanto.my-awesome-pokedex.com")!)

let router = try DefaultRouter(accepting: [customURLScheme, pokedexWeb, anotherWeb]) { registry in
    // Pokémon detail pages can be opened from all sources.
    registry.route("/pokemons/:pokedexID") { context in 
        let pokedexID: Int = try context.argument(named: "pokedexID") // Parse 'pokedexID' from URL
        if !Pokedex.isExist(pokedexID) { // Find the Pokémon by ID
            throw PokedexError.pokemonIsNotExist(pokedexID)
        }
        presentPokedexDetailViewController(of: pokedexID)
    }

    // Move related pages can be opened only from Custom URL Schemes
    registry.group(accepting: [customURLScheme]) { group in
        group.route("/moves/:move_name") { context in 
            let moveName: String = try context.argument(named: "move_name")
            presentMoveViewController(for: moveName)
        }
        group.route("/pokemons/:pokedexID/move") { context in 
            let pokedexID: Int = try context.argument(named: "pokedexID")
            presentPokemonMoveViewController(for: pokedexID)
        }
    }
}

You can share handlers between custom URL schemes and universal links. Could you try this version?

giginet avatar Nov 22 '21 11:11 giginet

Thanks for your great work! let me check!

aelam avatar Nov 26 '21 02:11 aelam