Giter Site home page Giter Site logo

chenxiancai / stcrouter Goto Github PK

View Code? Open in Web Editor NEW
20.0 3.0 2.0 90 KB

基于标准URL的iOS路由系统,可实现业务模块组件化,控制器之间零耦合,可实现黑白名单控制,可进行native降级到hybrid。

License: MIT License

Objective-C 99.06% Ruby 0.94%
router routing routing-engine route routes

stcrouter's Introduction

STCRouter

how to use

pod 'STCRouter'

standard URL format

http:\\host[:port][abs_path][:parameters][?query]#fragment

example

1.Use STCRouterCenter to register URL format for controller with params, like this:

[[STCRouterCenter defaultCenter].router  registerURLFormat:@"router:///root" 
toController:[ModalController class] withOptions:[[[STCRouterOption routerOptions] rootIndex:0] 
forDefaultParams:@{@"title": @"root"}]];

2.Setup blackList or whiteList, like this:

// 设置路由黑名单
[[STCRouterCenter defaultCenter] addBlackListWithObjects:@[@"com.apple.mobilesafari"]];

// 设置路由白名单
[[STCRouterCenter defaultCenter] addWhiteListInPathWithBIDs:@{@"root": @[@""]}];
[[STCRouterCenter defaultCenter] addWhiteListInPathWithBIDs:@{@"child": @[@"com.stevchen.STCRouter"]}];

Attention:
so, if you add a bundleId into blackList, app with this bundleId cann't open any path in router.
If you add route path with bundleId into whiteList, only app with bundleId in whiteList can open the route.

3.handle undefinded route, like this: 

[[STCRouterCenter defaultCenter].router setRouterForward:^(STCRouterParams *routerParams, STCRouterError *error) {
      //handle undefinded route
}];
 
4.open route, like this:

inside app without scheme

[[STCRouterCenter defaultCenter].router openURL:@"/child/user/child/user" withAnimated:YES extraParams:nil];

or outside app with scheme

[[STCRouterCenter defaultCenter].router openExternalURL:@"router:///root"];

or with stack controllers

[[STCRouterCenter defaultCenter].router openURL:@"router:///user/child/root"];

5.intercept route, like this:

 NSString *sourceApplication = [options valueForKey:UIApplicationOpenURLOptionsSourceApplicationKey];
 BOOL isFilter = [[STCRouterCenter defaultCenter] filterRouterWithUrl:url.absoluteString BID:sourceApplication];
 if (!isFilter) {
        [[STCRouterCenter defaultCenter].router openURL:url.absoluteString withAnimated:YES extraParams:nil];
 }
 
 6.set route from native to hybird, like this:
 
 [[STCRouterCenter defaultCenter].router changeURLFormat:@"router:///child" toHybridUrl:@"http://www.baidu.com"];
  
 you can revert it to native route:
 
 [[STCRouterCenter defaultCenter].router revertFromHybridWithURLFormat:@"router:///child"];

stcrouter's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

nadeal lzqvicli

stcrouter's Issues

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.