Skip to content
tfc edited this page Aug 10, 2017 · 9 revisions

Small use bundle.json file to configure UI routes.

Example:

{
  "version": "1.0.0",
  "bundles": [
    {
      "type":"app",
      "uri": "home",
      "pkg": ".bundle.home",
      "rules": {
        "page1": ".MyPage1",
        "page2": ".MyPage2"
      }
    }
  ]
}
属性 介绍
type 类型 可选 app lib web
uri 跳转转的url别名
pkg 包名
rules 包含的页面数组 如LoginActivity或LoginFragment 则 "login":"Login"

Main route

The main route is composed of the uri and the pkg. The pkg is the package id of the bundle.

From To
home
home/index.html
home.html
Bundle entrance

Bundle entrance

The default page or the principal class of the bundle.

Bundle type Default page
Android The launcher activity registered in AndroidManifest.xml
iOS The principal controller class defined in Info.plist
Web index.html

Usage

  • Android

    Small.openUri("home", context); // Turn to *.bundle.home.MainActivity (1)
  • iOS

    [Small openUri:@"home" fromController:controller]; // Turn to *.bundle.home.HomeController (2)
  • Web

    <a href="http://m.wequick.net/demo/home">home</a> <!-- Turn to (1) or (2) by current device -->

Sub routes

The sub routes is specified by the rules.

From To
home/$key
home/$key/index.html
home/$key.html
$valueActivity
$valueController

If the $value starts with ".", search the class in current bundle, otherwise search in global. This is just like the android:name definition for activities in AndroidManifest.xml.

Usage

  • Android

    Small.openUri("home/page1", context); // Turn to *.bundle.home.MyPage1Activity (1)
  • iOS

    [Small openUri:@"home/page1" fromController:controller]; // Turn to *.bundle.home.MyPage1Controller (2)
  • Web

    <a href="http://m.wequick.net/demo/home/page1">page1</a> <!-- Turn to (1) or (2) by current device -->

Passing parameters

Support passing parameters just like the web url way.

Passing

  • Android

    Small.openUri("detail?from=app.home", context);
  • iOS

    [Small openUri:@"detail?from=app.home" fromController:controller];
  • Web

    <a href="http://m.wequick.net/demo/detail.html?from=web.about">Call app.detail</a>

Receiving

  • Android

    // app.detail/MainActivity
    Uri uri = Small.getUri(this);
    if (uri != null) {
        String from = uri.getQueryParameter("from");
        // Do stuff by `from'
    }
  • iOS

    // DetailController.h
    @property (nonatomic, strong) NSString *from;
    
    // DetailController.m
    NSString *from = self.from;
  • Web

    var query = window.location.search.substr(1);
    // Do stuff by `query', something like `from=app.home'