-
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 -
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) -
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])
To run the example project, clone the repo, and run pod install from the Example directory first.
iOS 8.0+ and Xcode 11.0+ are required.
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 cocoapodsTo 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'
endThen, run the following command:
$ pod installCarthage 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 carthageTo 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.
URLRouter is available under the MIT license. See the LICENSE file for more info.