uniapp开发app框架在提升开发效率中的独特优势与应用探索
644
2022-10-26
mobile-router.js 是轻量级web端单页面框架
mobile-router.js — A lightweight single page bone for mobile web App
Online docs
DEMO - source code
require.js DEMO - source code
The mobile-router.js-demo is a simple mobile web app demo for mobile-router.js.
mobile-router.js-sample - A mobile-router.js demo like ui-router sample
中文 README
Less than 9k when gzipped
How can i install it?
Download a latest build from https://github.com/dolymood/mobile-router.js/releases it contains development and minified production files in build/ folder.
or use npm
npm install mobile-router.js
or use git clone
git clone https://github.com/dolymood/mobile-router.js.git
How can i use it?
M.router.init([ { path: '/', // route path cacheTemplate: false, // cacheTemplate option for current route animation: true, // animation option for current route aniClass: 'slideup', // switching effects option for current route getTemplate: function() { // sync return '/index template content'; }, onActive: function() { // 1.5.5+ // called when the route is actived, even before create `page-view` element }, callback: function() { // called after the page has been shown if (this.cached) return; // the page was cached in document. // do something ... }, onDestroy: function() { // destroy }, onEnter: function(paramName) { // 1.5.3+ // called when the page will show }, onLeave: function() { // 1.5.3+ // called when the page will hide } }, { path: '/m/:paramName', getTemplate: function(cb) { // async var that = this; // that.params - params info // that.query - query info setTimeout(function() { cb('/m/' + that.params.paramName + ' template content'); }, 200); }, callback: function(paramName) { if (this.cached) return; // do something ... }, onDestroy: function() { // destroy } }, { // support redirectTo , string url or function (1.5.5+) path: '/redirectTo/:rtPath', redirectPushState: false, // default true, enable `pushState` when redirectTo is actived redirectTo: function(rtPath) { console.log('redirectTo', arguments, this); return '/' + rtPath; } }, { // support redirectTo , string url or function (1.5.5+) // if redirectTo route have getTemplate then the `page-view` will // be created, looks like a normal route. The redirectTo will be actived // after the route's callback is called path: '/contacts', getTemplate: contacts.getTemplate, onEnter: contacts.onEnter, onLeave: contacts.onLeave, callback: contacts.controller, onDestroy: contacts.onDestroy, redirectTo: '/contacts/list', redirectPushState: false, children: { // Nested routes & views! (1.5.0+) viewsSelector: '.content', cacheViewsNum: 1, routes: [ { // all contacts path: '/list', getTemplate: list.getTemplate, onEnter: list.onEnter, onLeave: list.onLeave, callback: list.controller, onDestroy: list.onDestroy } ] } }, { path: '/d', getTemplate: def.getTemplate, onEnter: def.onEnter, onLeave: def.onLeave, callback: def.controller, onDestroy: def.onDestroy, children: { viewsSelector: '.content', cacheViewsNum: 1, routes: [ { // sub default route path: '/', getTemplate: defSub.getTemplate, onEnter: defSub.onEnter, onLeave: defSub.onLeave, callback: defSub.controller, onDestroy: defSub.onDestroy } ] } }, { // Nested routes & views! (1.5.0+) path: '/b/:bid', getTemplate: function(cb) { var path = this.path.substr(1); setTimeout(function() { var lis = ''; var t; // build sub view link for (var i = 1; i <= 4; i++) { t = path + '/s' + i; lis += '
sub content
Advantages?
Lightweight, Easy. Nested routes & views (1.5.0+). No Dependencies. You can use it with jquery, zepto, iscroll or others. Cache templates automatically. Good for SEO. You can render pages on server. Cache pages automatically. Default cache pages number is 3. Switching pages use CSS animation. History mode: history, hashbang or abstract
About some configs
The priority of get animation, aniClass or cacheTemplate config's value is:
`data-xxx` -> route config -> global config
About examples/
index.html: basic usage, getTemplate config, and data-rel=back attribute config on link element for reverse animation direction. index1.html: link element's data-href attribute config (as same as abstract=true) , and disable one route animation. index2.html: disable animation. index3.html: disable cacheTemplate. index4.html: set global aniClass. index5.html: set aniClass in two ways. index6.html: set cacheTemplate of one route. index7.html: set M.history config abstract=true. index8.html: nested routes and views. requirejs/: use require.js
About SEO
The server can response HTML with cpmplete content
License
The MIT License
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~