Skip to content

MichaelRow/MRRouter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URLRouter

Swift Version Carthage compatible License Platform

How to Use

  1. Use the Router singleton.

    let router = Router.shared
    
    //you'd better set the nest window to prevent no navigating.
    router.nestWindow = YOUR_APP_MAIN_WINDOW
    
  2. Register view controllers.

    // You can get the routing parameters if your VCs conform to RoutableViewController protocol.
    // The VC stack management take no effects if you don't implemente the protocol.
    class GeneralVC: UIViewController, RoutableViewController {
        static var stackLevel: StackLevel { return .lowest }
        var parameters: [String : Any]
        required init(_ parameters: [String : Any]) {
            super.init(nibName: nil, bundle: nil)
        }
    }
    
    class UserVC: UIViewController, RoutableViewController {
        static var stackLevel: StackLevel { return .low }
        var parameters: [String : Any]
        required init(_ parameters: [String : Any]) {
            super.init(nibName: nil, bundle: nil)
        }
    }
    
    // Not conforming to the protocol is OK as also.
    class SettingsVC: UIViewController {}
    
    router.register(pattern: "router://general", viewControllerType: GeneralVC.self)
    router.register(pattern: "router://settings", viewControllerType: SettingsVC.self)
    
    // use <NAME> in the URL path components match all possible values, and you can get it as a parameter from the parameters dictionary.
    router.register(pattern: "router://user/<name>", viewControllerType: UserVC.self)
    
  3. Open the URL registered. All the annorying measures will be perfectly managed by the navigator, just open it.

    // open use push by default
    router.open(url: "router://general")
    
    // or use push directly
    router.push(url: "router://settings", parameters: ["WiFi":true], option: [.withoutAnimation]) { error in
        if error == nil {
            print("Navigation Complete!")
        }
    }
    
    // you can present and wrap the VC in a navigation controller by adding the option
    router.present(url: "router://user/MichaelRow", option: [.wrapInNavigation])
    

Example Project

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS 8.0+ and Xcode 11.0+ are required.

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like URLRouter in your projects. See the "Getting Started" guide for more information. You can install it with the following command:

$ gem install cocoapods

Podfile

To integrate URLRouter into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/MichaelRow/PodSpecs.git'
platform :ios, '8.0'

target 'YourTargetName' do
pod 'URLRouter'
end

Then, run the following command:

$ pod install

Installation with Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate URLRouter into your Xcode project using Carthage, specify it in your Cartfile:

github "MichaelRow/URLRouter"

Run carthage to build the framework and drag the built URLRouter.framework into your Xcode project.

License

URLRouter is available under the MIT license. See the LICENSE file for more info.

About

A swifty router

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published