Giter VIP home page Giter VIP logo

router's Introduction

Router

Build Status

A micro routing library written in swift, primarily for deep linking use cases

Installation

Embedded frameworks require a minimum deployment target of iOS 8.

Integration can be done either Manually or through Cocoapods

Cocoapods

CocoaPods is a dependency manager for Cocoa projects.

CocoaPods 0.36 adds supports for Swift and embedded frameworks. You can install it with the following command:

$ gem install cocoapods

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

platform :ios, '8.0'
use_frameworks!

pod 'Router', '~> 1.0.0'

Then, run the following command:

$ pod install

Requirements

  • iOS 8.0+
  • Xcode 7.1
  • Swift 2.0
  • Cocoapods 0.36+ (Optional)

Simple Usage

import Router

// create your router
let router = Router()

// bind your routes with a callback
router.bind("/route/:id") { (req) -> Void in
    print(req.param("id")!)
}

// match a route
let url = NSURL(string: "routerapp://route/abc123")!
let route = router.match(url)

Route binding

Bind a closure to a route definition

router.bind("/route/:id") { (req) -> Void in
    print(req.param("id")!)
}

Route Matching

Matches an incoming url to a route in the Router. If a match is made, the closure is executed and the matched route is returned

let url = NSURL(string: "routerapp://route/abc123")!
let route = router.match(url)

Request Object

A request object is accessible in the closure arg. Access url params in the closure (ie. id from /route/:id) by using .param() function

router.bind("/route/:id") { (req) -> Void in
	let id = req.param("id")!
}

Access query string params from the callback (ie. /route/123?foo=bar) by using .query() function

router.bind("/route/:id") { (req) -> Void in
	let foo = req.query("foo")! 
}

Deeplinking to the Sample app

  • Install the RouterExample app
  • Close the app
  • Open safari
  • Type routerapp://route/one into the address bar to access View One
  • Exit out of the app
  • Type routerapp://route/one/abc123 into the address bar to access View Two

Found a bug?

  • Open up an issue
  • Write test(s) that reproduce the issue
  • Fix the issue
  • Send a Pull Request

Want a feature request?

  • Open up an Issue
  • Write test(s) around the new feature
  • Implement the feature
  • Send a Pull Request

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.