;
253 | beforeEnter?: guardHookRule;
254 | meta?: any;
255 | [propName: string]: any;
256 | }
257 |
258 | export declare function runtimeQuit(title?: string | undefined): void;
259 |
260 | export declare interface startAnimationRule {
261 | animationType?: startAnimationType;
262 | animationDuration?: number;
263 | }
264 |
265 | export declare type startAnimationType = 'slide-in-right' | 'slide-in-left' | 'slide-in-top' | 'slide-in-bottom' | 'pop-in' | 'fade-in' | 'zoom-out' | 'zoom-fade-out' | 'none';
266 |
267 | export declare interface totalNextRoute extends h5NextRule, navtoRule {
268 | path: string;
269 | [propName: string]: any;
270 | }
271 |
272 | export declare interface uniBackApiRule {
273 | delta?: number;
274 | animationDuration?: number;
275 | animationType?: endAnimationType;
276 | }
277 |
278 | export declare interface uniBackRule {
279 | from: string;
280 | }
281 |
282 | export declare interface uniNavApiRule {
283 | url: string;
284 | openType?: 'appLaunch';
285 | query?: objectAny;
286 | path?: string;
287 | detail?: {
288 | [propName: string]: any;
289 | };
290 | animationType?: startAnimationType;
291 | animationDuration?: number;
292 | events?: {
293 | [propName: string]: any;
294 | };
295 | success?: Function;
296 | fail?: Function;
297 | complete?: Function;
298 | }
299 |
300 | export { }
301 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/hybrid/html/local.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
9 |
10 |
11 |
12 |
这是加载的本地html页面
13 |
14 |
15 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import App from './App'
3 | import {router, RouterMount} from './router.js'
4 | import routerLInk from './dist/link.vue'
5 | Vue.component('RouterLink1', routerLInk)
6 |
7 | Vue.use(router)
8 |
9 | // import VConsole from 'vconsole'
10 | // var vConsole = new VConsole();
11 |
12 | App.mpType = 'app'
13 |
14 | // Vue.mixin({
15 | // onShow(){
16 | // if(this._uid!=0){
17 | // router.forceGuardEach()
18 | // }
19 | // }
20 | // })
21 |
22 | const app = new Vue({
23 | ...App
24 | })
25 |
26 | // v1.3.5起 H5端 你应该去除原有的app.$mount();使用路由自带的渲染方式
27 | // #ifdef H5
28 | RouterMount(app, router, '#app')
29 | // #endif
30 |
31 | // #ifndef H5
32 | app.$mount(); // 为了兼容小程序及app端必须这样写才有效果
33 | // #endif
34 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name" : "uni-simple-router2.0",
3 | "appid" : "__UNI__DB9F679",
4 | "description" : "",
5 | "versionName" : "1.0.0",
6 | "versionCode" : "100",
7 | "transformPx" : false,
8 | /* 5+App特有相关 */
9 | "app-plus" : {
10 | "usingComponents" : true,
11 | "nvueCompiler" : "uni-app",
12 | "compilerVersion" : 3,
13 | "splashscreen" : {
14 | "alwaysShowBeforeRender" : false,
15 | "waiting" : true,
16 | "autoclose" : false,
17 | "delay" : 0
18 | },
19 | /* 模块配置 */
20 | "modules" : {
21 | "Statistic" : {}
22 | },
23 | /* 应用发布信息 */
24 | "distribute" : {
25 | /* android打包配置 */
26 | "android" : {
27 | "permissions" : [
28 | "",
29 | "",
30 | "",
31 | "",
32 | "",
33 | "",
34 | "",
35 | "",
36 | "",
37 | "",
38 | "",
39 | "",
40 | "",
41 | "",
42 | "",
43 | "",
44 | "",
45 | "",
46 | "",
47 | "",
48 | ""
49 | ],
50 | "autoSdkPermissions" : true
51 | },
52 | /* ios打包配置 */
53 | "ios" : {},
54 | /* SDK配置 */
55 | "sdkConfigs" : {
56 | "ad" : {}
57 | }
58 | },
59 | "uniStatistics" : {
60 | "enable" : true
61 | }
62 | },
63 | /* 快应用特有相关 */
64 | "quickapp" : {},
65 | /* 小程序特有相关 */
66 | "mp-weixin" : {
67 | "appid" : "wx857b3a454bf68899",
68 | "setting" : {
69 | "urlCheck" : false
70 | },
71 | "usingComponents" : true
72 | },
73 | "mp-alipay" : {
74 | "usingComponents" : true
75 | },
76 | "mp-baidu" : {
77 | "usingComponents" : true
78 | },
79 | "mp-toutiao" : {
80 | "usingComponents" : true
81 | },
82 | "uniStatistics" : {
83 | "enable" : false
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "uni-simple-router2.0",
3 | "version": "1.0.0",
4 | "lockfileVersion": 1,
5 | "requires": true,
6 | "dependencies": {
7 | "uni-read-pages": {
8 | "version": "1.0.5",
9 | "resolved": "https://r.cnpmjs.org/uni-read-pages/download/uni-read-pages-1.0.5.tgz",
10 | "integrity": "sha1-RSyNyqiXe7rvYAkJvpJsjZcEOHw="
11 | },
12 | "vconsole": {
13 | "version": "3.3.4",
14 | "resolved": "https://registry.npmjs.org/vconsole/-/vconsole-3.3.4.tgz",
15 | "integrity": "sha512-9yihsic96NPoMLQx/lCQwH9d89H0bbMW3LZPzo/t4yGQcS1X+vTCe9OHm1XSH7WNxzGDmcSwBiKLsFGwvJpQBg=="
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "uni-simple-router2.0",
3 | "version": "1.0.0",
4 | "main": "main.js",
5 | "scripts": {
6 | "test": "echo \"Error: no test specified\" && exit 1"
7 | },
8 | "author": "",
9 | "license": "ISC",
10 | "dependencies": {
11 | "uni-read-pages": "^1.0.5",
12 | "vconsole": "^3.3.4"
13 | },
14 | "devDependencies": {},
15 | "keywords": [],
16 | "description": ""
17 | }
18 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages": [
3 | // // #ifdef APP-PLUS
4 | // {
5 | // "path" : "pages/empty/empty",
6 | // "name":"empty",
7 | // "style" :
8 | // {
9 | // "navigationBarTitleText": "",
10 | // "enablePullDownRefresh": false
11 | // }
12 |
13 | // },
14 | // // #endif
15 | {
16 | "path": "pages/index/index",
17 | "name": "index",
18 | "aliasPath": "/"
19 | },
20 | {
21 | "path": "pages/login/login",
22 | "name": "login",
23 | "style": {
24 | "navigationBarTitleText": "",
25 | "enablePullDownRefresh": false
26 | }
27 | },
28 | {
29 | "path": "pages/page2/page2",
30 | "aliasPath": "/page2/:id",
31 | "name": "page2"
32 | },
33 | {
34 | "path": "pages/page3/page3",
35 | "aliasPath": "/:name/page3/:id",
36 | "name": "page3"
37 | },
38 | {
39 | "path": "pages/404/404",
40 | "name": "404"
41 | }, {
42 | "path": "pages/navigate/navigate",
43 | "style": {
44 | "navigationBarTitleText": "",
45 | "enablePullDownRefresh": false
46 | }
47 | }, {
48 | "path": "pages/other/other",
49 | "name": "tabother",
50 | "style": {
51 | "navigationBarTitleText": "",
52 | "enablePullDownRefresh": false
53 | }
54 |
55 | }, {
56 | "path": "pages/page4/page4",
57 | "style": {
58 | "navigationBarTitleText": "",
59 | "enablePullDownRefresh": false
60 | }
61 |
62 | }, {
63 | "path": "pages/builtIn/builtIn",
64 | "style": {
65 | "navigationBarTitleText": "",
66 | "enablePullDownRefresh": false
67 | }
68 |
69 | }, {
70 | "path": "pages/routerlink/routerlink",
71 | "name": "routerLink",
72 | "style": {
73 | "navigationBarTitleText": "",
74 | "enablePullDownRefresh": false
75 | }
76 |
77 | }, {
78 | "path": "pages/relativePath/relativePath",
79 | "style": {
80 | "navigationBarTitleText": "",
81 | "enablePullDownRefresh": false
82 | }
83 |
84 | }, {
85 | "path": "pages/relativePath/relativePath2",
86 | "name": "relativePath2",
87 | "style": {
88 | "navigationBarTitleText": "",
89 | "enablePullDownRefresh": false
90 | }
91 |
92 | }, {
93 | "path": "pages/dynamicPage/dynamicPage",
94 | "name": "dynamicPage",
95 | "aliasPath": "/dynamicPage",
96 | "style": {
97 | "navigationBarTitleText": "",
98 | "enablePullDownRefresh": false
99 | }
100 |
101 | }, {
102 | "path": "pages/guard/guard",
103 | "name": "guard",
104 | "style": {
105 | "navigationBarTitleText": "",
106 | "enablePullDownRefresh": false
107 | }
108 |
109 | }, {
110 | "path": "pages/relativePathP",
111 | "style": {
112 | "navigationBarTitleText": "",
113 | "enablePullDownRefresh": false
114 | }
115 |
116 | }, {
117 | "path": "pages/animation/animation",
118 | "name": "animation",
119 | "style": {
120 | "navigationBarTitleText": "",
121 | "enablePullDownRefresh": false,
122 | "app-plus": {
123 | "animationType": "slide-in-bottom",
124 | "animationDuration": 600
125 | }
126 | },
127 | "animation": {
128 | "animationType": "zoom-fade-out",
129 | "animationDuration": 500
130 | }
131 |
132 | }, {
133 | "path": "pages/beforeRouteLeave/beforeRouteLeave",
134 | "aliasPath": "/beforeRouteLeave",
135 | "name": "beforeRouteLeave",
136 | "style": {
137 | "navigationBarTitleText": "",
138 | "enablePullDownRefresh": false
139 | }
140 |
141 | }, {
142 | "path": "pages/events/events",
143 | "name": "events",
144 | "style": {
145 | "navigationBarTitleText": "",
146 | "enablePullDownRefresh": false
147 | }
148 |
149 | }, {
150 | "path": "pages/eventsEmit/eventsEmit",
151 | "name": "eventsEmit",
152 | "style": {
153 | "navigationBarTitleText": "",
154 | "enablePullDownRefresh": false
155 | }
156 |
157 | }, {
158 | "path": "pages/nvue1/nvue1",
159 | "name": "nvue1",
160 | "style": {
161 | "navigationBarTitleText": "",
162 | "enablePullDownRefresh": false
163 | }
164 |
165 | }, {
166 | "path": "pages/webView/webView",
167 | "name": "webView",
168 | "style": {
169 | "navigationBarTitleText": "",
170 | "enablePullDownRefresh": false
171 | }
172 |
173 | }
174 |
175 | ],
176 | "tabBar": {
177 | "list": [{
178 | "pagePath": "pages/index/index",
179 | "iconPath": "static/component.png",
180 | "selectedIconPath": "static/componentHL.png",
181 | "text": "首页"
182 | }, {
183 | "pagePath": "pages/other/other",
184 | "iconPath": "static/extui.png",
185 | "selectedIconPath": "static/extuiHL.png",
186 | "text": "其他"
187 | }]
188 | },
189 | "globalStyle": {
190 | "navigationBarTextStyle": "black",
191 | "navigationBarTitleText": "uni-app",
192 | "navigationBarBackgroundColor": "#F8F8F8",
193 | "backgroundColor": "#F8F8F8"
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/404/404.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | 迷路啦,找不到页面
4 |
5 |
6 |
7 |
23 |
24 |
27 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/animation/animation.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | 当前页为app端测试跳转动画页面
4 |
5 |
6 |
7 |
8 |
40 |
41 |
44 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/beforeRouteLeave/beforeRouteLeave.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | beforeRouteLeave
4 |
7 |
8 |
9 |
10 |
41 |
42 |
45 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/builtIn/builtIn.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
74 |
75 |
78 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/dynamicPage/dynamicPage.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
27 |
28 |
31 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/empty/empty.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/events/events.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | events
4 |
5 |
6 |
7 |
8 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/eventsEmit/eventsEmit.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | eventsEmit
4 |
5 |
6 |
7 |
28 |
29 |
32 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/guard/guard.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
32 |
33 |
36 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/index/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {{title}}
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
28 |
164 |
165 |
192 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/login/login.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | 登录页面
4 |
5 |
6 |
7 |
8 |
40 |
41 |
44 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/navigate/navigate.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
221 |
222 |
225 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/nvue1/nvue1.nvue:
--------------------------------------------------------------------------------
1 |
2 |
3 | nvue1
4 |
5 |
6 |
7 |
8 |
22 |
23 |
26 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/other/other.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | 其他页面
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/page2/page2.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | 页面2
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
71 |
72 |
75 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/page3/page3.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | 页面3
4 |
5 |
6 |
7 |
19 |
20 |
23 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/page4/page4.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | page4
4 |
5 |
6 |
7 |
36 |
37 |
40 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/relativePath/relativePath.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
11 |
15 |
19 |
23 |
24 |
25 |
26 |
42 |
43 |
46 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/relativePath/relativePath2.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | relativePath2
4 |
5 |
6 |
7 |
19 |
20 |
23 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/relativePathP.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | 相对路径的顶级页面
4 |
5 |
9 |
10 |
11 |
12 |
13 |
29 |
30 |
33 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/routerlink/routerlink.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
10 | ----------分割线--------
11 |
14 |
15 |
16 |
19 |
20 |
21 | ----------分割线--------
22 |
23 |
24 |
29 |
30 |
31 |
32 | ----------分割线--------
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | ----------分割线--------
41 |
42 |
43 |
44 |
45 |
46 |
47 | ----------分割线--------
48 |
49 |
50 |
51 |
52 |
53 |
54 |
84 |
85 |
88 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/pages/webView/webView.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
23 |
24 |
27 |
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/router.js:
--------------------------------------------------------------------------------
1 | import {
2 | RouterMount,
3 | createRouter,
4 | runtimeQuit
5 | } from './dist/uni-simple-router.js';
6 |
7 |
8 | let pageHookAnimationEnd=null;
9 | const pageHookAnimation=new Promise(resolve=>pageHookAnimationEnd=resolve);
10 |
11 | // #ifndef APP-PLUS
12 | pageHookAnimationEnd();
13 | // #endif
14 |
15 | let first = null;
16 | const router = createRouter({
17 | platform: process.env.VUE_APP_PLATFORM,
18 | APP:{
19 | animation:{
20 | animationType:'slide-in-top',
21 | animationDuration:300
22 | },
23 | registerLoadingPage:true,
24 | loadingPageStyle:()=>JSON.parse('{"backgroundColor":"#FFCCCC"}'),
25 | loadingPageHook:async (view)=>{
26 | console.log('------------loadingPageHook--------------')
27 | view.show();
28 | const [,{screenWidth}]=await uni.getSystemInfo();
29 | view.drawBitmap('/static/wait3.gif', {}, {
30 | top: 'auto',
31 | left: 'auto',
32 | width: screenWidth+'px',
33 | height: 'auto'
34 | });
35 | plus.navigator.closeSplashscreen();
36 | setTimeout(()=>{
37 | pageHookAnimationEnd();
38 | },3500)
39 | },
40 | launchedHook:()=>{
41 | plus.navigator.closeSplashscreen();
42 | console.log('APP加载完成啦')
43 | }
44 | },
45 | applet:{
46 | animationDuration:300
47 | },
48 | routerErrorEach:({type,level,...args})=>{
49 | console.log({type,level,...args});
50 | if(type===3){
51 | router.$lockStatus=false;
52 | // #ifdef APP-PLUS
53 | if(level==1&&args.uniActualData.from==='backbutton'){
54 | runtimeQuit();
55 | }
56 | // #endif
57 | }else if(type===0){
58 | router.$lockStatus=false;
59 | }
60 |
61 | },
62 | beforeProxyHooks: {
63 | onLaunch(options,next){
64 | console.log(this)
65 | setTimeout(()=>{
66 | return next([{
67 | ...options
68 | }])
69 | },3000)
70 | },
71 | onLoad: function(options, next,router) {
72 | console.log(options);
73 | console.log(this)
74 | next([
75 | {name:111}
76 | ])
77 | },
78 |
79 | },
80 | debugger:false,
81 | routes: [
82 | ...ROUTES,
83 | {
84 | path: '*',
85 | redirect:(...args)=>{
86 | return {name:'404'}
87 | }
88 | },
89 | ]
90 | });
91 | console.log(router)
92 | let count=0;
93 | router.beforeEach(async (to, from, next) => {
94 | count++
95 | // if(to.name=='index' && to.BACKTYPE=='navigateBack'){
96 | // next(false);
97 | // }else{
98 | // next();
99 | // }
100 |
101 | await pageHookAnimation;
102 | next();
103 |
104 | // if(count==1){
105 | // next({
106 | // path:'/pages/login/login',
107 | // NAVTYPE:'replaceAll'
108 | // })
109 | // }else{
110 | // next();
111 | // }
112 |
113 | });
114 | router.afterEach((to, from, next) => {
115 | console.log('afterEach---跳转结束')
116 | });
117 |
118 | export {
119 | router,
120 | RouterMount
121 | }
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/static/component.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilurianYang/uni-simple-router/a10bea6db12918ed76c579d205a499f04e69cf9f/examples/uni-simple-router2.0/static/component.png
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/static/componentHL.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilurianYang/uni-simple-router/a10bea6db12918ed76c579d205a499f04e69cf9f/examples/uni-simple-router2.0/static/componentHL.png
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/static/extui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilurianYang/uni-simple-router/a10bea6db12918ed76c579d205a499f04e69cf9f/examples/uni-simple-router2.0/static/extui.png
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/static/extuiHL.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilurianYang/uni-simple-router/a10bea6db12918ed76c579d205a499f04e69cf9f/examples/uni-simple-router2.0/static/extuiHL.png
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/static/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilurianYang/uni-simple-router/a10bea6db12918ed76c579d205a499f04e69cf9f/examples/uni-simple-router2.0/static/logo.png
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/static/wait.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilurianYang/uni-simple-router/a10bea6db12918ed76c579d205a499f04e69cf9f/examples/uni-simple-router2.0/static/wait.gif
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/static/wait2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilurianYang/uni-simple-router/a10bea6db12918ed76c579d205a499f04e69cf9f/examples/uni-simple-router2.0/static/wait2.gif
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/static/wait3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilurianYang/uni-simple-router/a10bea6db12918ed76c579d205a499f04e69cf9f/examples/uni-simple-router2.0/static/wait3.gif
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/uni.scss:
--------------------------------------------------------------------------------
1 | /**
2 | * 这里是uni-app内置的常用样式变量
3 | *
4 | * uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
5 | * 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
6 | *
7 | */
8 |
9 | /**
10 | * 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
11 | *
12 | * 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
13 | */
14 |
15 | /* 颜色变量 */
16 |
17 | /* 行为相关颜色 */
18 | $uni-color-primary: #007aff;
19 | $uni-color-success: #4cd964;
20 | $uni-color-warning: #f0ad4e;
21 | $uni-color-error: #dd524d;
22 |
23 | /* 文字基本颜色 */
24 | $uni-text-color:#333;//基本色
25 | $uni-text-color-inverse:#fff;//反色
26 | $uni-text-color-grey:#999;//辅助灰色,如加载更多的提示信息
27 | $uni-text-color-placeholder: #808080;
28 | $uni-text-color-disable:#c0c0c0;
29 |
30 | /* 背景颜色 */
31 | $uni-bg-color:#ffffff;
32 | $uni-bg-color-grey:#f8f8f8;
33 | $uni-bg-color-hover:#f1f1f1;//点击状态颜色
34 | $uni-bg-color-mask:rgba(0, 0, 0, 0.4);//遮罩颜色
35 |
36 | /* 边框颜色 */
37 | $uni-border-color:#c8c7cc;
38 |
39 | /* 尺寸变量 */
40 |
41 | /* 文字尺寸 */
42 | $uni-font-size-sm:24rpx;
43 | $uni-font-size-base:28rpx;
44 | $uni-font-size-lg:32rpx;
45 |
46 | /* 图片尺寸 */
47 | $uni-img-size-sm:40rpx;
48 | $uni-img-size-base:52rpx;
49 | $uni-img-size-lg:80rpx;
50 |
51 | /* Border Radius */
52 | $uni-border-radius-sm: 4rpx;
53 | $uni-border-radius-base: 6rpx;
54 | $uni-border-radius-lg: 12rpx;
55 | $uni-border-radius-circle: 50%;
56 |
57 | /* 水平间距 */
58 | $uni-spacing-row-sm: 10px;
59 | $uni-spacing-row-base: 20rpx;
60 | $uni-spacing-row-lg: 30rpx;
61 |
62 | /* 垂直间距 */
63 | $uni-spacing-col-sm: 8rpx;
64 | $uni-spacing-col-base: 16rpx;
65 | $uni-spacing-col-lg: 24rpx;
66 |
67 | /* 透明度 */
68 | $uni-opacity-disabled: 0.3; // 组件禁用态的透明度
69 |
70 | /* 文章场景相关 */
71 | $uni-color-title: #2C405A; // 文章标题颜色
72 | $uni-font-size-title:40rpx;
73 | $uni-color-subtitle: #555555; // 二级标题颜色
74 | $uni-font-size-subtitle:36rpx;
75 | $uni-color-paragraph: #3F536E; // 文章段落颜色
76 | $uni-font-size-paragraph:30rpx;
--------------------------------------------------------------------------------
/examples/uni-simple-router2.0/vue.config.js:
--------------------------------------------------------------------------------
1 | const TransformPages = require('uni-read-pages')
2 | const {webpack} = new TransformPages()
3 | module.exports = {
4 | configureWebpack: {
5 | plugins: [
6 | new webpack.DefinePlugin({
7 | ROUTES: webpack.DefinePlugin.runtimeValue(() => {
8 | const tfPages = new TransformPages({
9 | includes: ['path', 'name', 'aliasPath','animation']
10 | });
11 | return JSON.stringify(tfPages.routes)
12 | }, true )
13 | })
14 | ]
15 | }
16 | }
--------------------------------------------------------------------------------
/github.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # author hhyang
4 | # home https://github.com/SilurianYang
5 |
6 | printf "\n -------------- Ctrl+D可以退出程序 --------------- \n\n"
7 |
8 | select name in "auto" "status" "add" "commit" "push" "pull" "branch" "checkout" "*"; do
9 | case "$name" in
10 | # 自动同步文件
11 | "auto")
12 | cp -avx ./examples/node_modules/uni-simple-router/* ./npm-package
13 | rm -rf ./npm-package/package-lock.json
14 | cp -avx ./README.md ./npm-package
15 | cp -avx ./package.json ./npm-package
16 | cp -avx ./npm-package/* ./src
17 | rm -rf ./src/README.md
18 | rm -rf ./src/package.json
19 |
20 | printf "\n -------------- 自动化构建目录完毕 --------------- \n\n"
21 | ;;
22 |
23 | # 查询status
24 | "status")
25 | git status
26 | printf "\n -------------- 查询完毕 --------------- \n\n"
27 | ;;
28 |
29 | # 添加文件 .或* 全部文件 可自定义文件路径
30 | "add")
31 | while read -p "请输入更多提交命令 【默认全部.】 :" add; do
32 | if [[ "$add" == "" ]]; then
33 | eval "git add ."
34 | else
35 | eval "git add ${add}"
36 | fi
37 | printf "\n -------------- 添加完成 --------------- \n\n"
38 | break
39 | done
40 | ;;
41 |
42 | # 提交文件
43 | "commit")
44 | while read -p "请输入提交信息:" readme; do
45 | if [[ "$readme" != "" ]]; then
46 | eval "git commit -m '${readme}'"
47 | printf "\n -------------- 提交本地完成 --------------- \n\n"
48 | break
49 | else
50 | printf "\n警告====> 提交信息不能为空! \n \n"
51 | fi
52 | done
53 | ;;
54 |
55 | # 推送到服务端
56 | "push")
57 | read -p "请输入提交的分支(不输入默认主分支 [master] ):" branch
58 | printf "\n\n -------------- 正在推送github,请稍后.... --------------- \n\n"
59 | if [[ "$branch" == "" ]]; then
60 | git push
61 | else
62 | eval "git push origin ${branch}"
63 | fi
64 | printf "\n -------------- 推送github完成 --------------- \n\n"
65 | ;;
66 |
67 | # 拉取最新代码
68 | "pull")
69 | printf "\n\n -------------- 正在拉取,请稍后.... --------------- \n\n"
70 | git pull
71 | printf "\n -------------- 正在拉取完成 --------------- \n\n"
72 | ;;
73 |
74 | # 切换分支操作
75 | "branch")
76 | read -p "请输入添加更多指令 【分支】 :" branchs
77 | if [[ "$branchs" == "" ]]; then
78 | printf "\n分支列表如下:\n\n"
79 | git branch
80 | else
81 | eval "git branch ${branchs}"
82 | fi
83 | printf "\n -------------- 分支操作完毕 --------------- \n\n"
84 | ;;
85 | #
86 | "checkout")
87 | read -p "请输入添加更多指令 【默认切换到master】 :" out
88 | if [[ "$out" == "" ]]; then
89 | git checkout master
90 | else
91 | eval "git checkout ${out}"
92 | fi
93 | printf "\n -------------- 执行完毕 --------------- \n\n"
94 | ;;
95 | # 自定义指令
96 | *)
97 | while read -p "请输入自定义命令 【输入:q退出】:" code; do
98 | if [[ "$code" == ":q" ]];then
99 | printf "\n"
100 | break
101 | fi
102 | printf "\n\n -------------- 正在执行,请稍后.... --------------- \n\n"
103 | eval "$code"
104 | printf "\n -------------- 执行完毕 --------------- \n\n"
105 | done
106 | esac
107 | done
108 |
--------------------------------------------------------------------------------
/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | preset: 'ts-jest',
3 | testEnvironment: 'node',
4 | moduleDirectories:['node_modules','src']
5 | };
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "uni-simple-router",
3 | "version": "2.0.8-beta.4",
4 | "description": "> 一个更为简洁的[Vue-router](https://router.vuejs.org/zh/),专为 [uni-app](https://uniapp.dcloud.io/) 量身打造",
5 | "main": "dist/uni-simple-router.js",
6 | "types": "dist/uni-simple-router.d.ts",
7 | "dependencies": {
8 | "@microsoft/api-extractor": "^7.11.2",
9 | "@types/node": "^14.14.2",
10 | "@types/webpack": "^4.41.23",
11 | "@types/webpack-env": "^1.15.3",
12 | "copy-webpack-plugin": "^5.1.2",
13 | "jest-cli": "^26.6.3",
14 | "lodash.merge": "^4.6.2",
15 | "node-cmd": "^5.0.0",
16 | "path-to-regexp": "^1.8.0",
17 | "ts-loader": "^8.0.5",
18 | "typescript": "^4.0.3",
19 | "webpack": "^5.1.0",
20 | "webpack-cli": "^4.0.0"
21 | },
22 | "devDependencies": {
23 | "@types/jest": "^26.0.22",
24 | "@typescript-eslint/eslint-plugin": "^4.4.1",
25 | "@typescript-eslint/parser": "^4.4.1",
26 | "eslint": "^7.11.0",
27 | "jest": "^26.6.3",
28 | "lodash": "^4.17.20",
29 | "rimraf": "^3.0.2",
30 | "ts-jest": "^26.5.5",
31 | "ts-node": "^9.0.0",
32 | "vconsole": "^3.3.4",
33 | "webpack-merge": "^5.2.0"
34 | },
35 | "scripts": {
36 | "dev": "webpack --watch --progress --config webpack/webpack.dev.js",
37 | "dist": "webpack --progress --config webpack/webpack.prod.js",
38 | "dist:dts": "api-extractor run --local --verbose",
39 | "lint": "eslint --ext .js,.ts src",
40 | "lintFix": "eslint --ext .js,.ts src --fix",
41 | "test": "jest test/query-toggle.spec.ts",
42 | "publish": "node ./publish/index.js",
43 | "build": "node ./publish/build.js"
44 | },
45 | "repository": {
46 | "type": "git",
47 | "url": "git+https://github.com/SilurianYang/uni-simple-router.git"
48 | },
49 | "keywords": [
50 | "router",
51 | "uni-app-router",
52 | "interceptor",
53 | "uni-app",
54 | "uniapp"
55 | ],
56 | "author": "hhyang",
57 | "license": "MIT",
58 | "bugs": {
59 | "url": "https://github.com/SilurianYang/uni-simple-router/issues"
60 | },
61 | "homepage": "https://github.com/SilurianYang/uni-simple-router#readme"
62 | }
63 |
--------------------------------------------------------------------------------
/publish/build.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs');
2 | const {resolve} = require('path');
3 | const {exec} = require('child_process');
4 | const packageJSON = require('../package.json');
5 |
6 | function rootPath(dir) {
7 | return resolve(process.cwd(), dir);
8 | }
9 |
10 | exec('npm run dist && npm run dist:dts', { cwd: process.cwd() }, (err, stdout, stderr) => {
11 | if (err) {
12 | return console.log(err);
13 | }
14 |
15 | console.log(stderr);
16 |
17 | const doFile = rootPath('dist/uni-simple-router.d.ts');
18 | fs.writeFileSync(doFile, `
19 | // @ts-ignore
20 | declare module 'vue/types/vue' {
21 | interface Vue {
22 | $Router: Router;
23 | $Route: routeRule;
24 | }
25 | }
26 | `, {flag: 'a+'});
27 |
28 | console.log(
29 | `✅ ${packageJSON.name}@${packageJSON.version}----------------打包成功`
30 | );
31 | });
32 |
--------------------------------------------------------------------------------
/publish/index.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs');
2 | const {resolve} = require('path');
3 | const {exec} = require('child_process');
4 | const packageJSON = require('../package.json');
5 |
6 | function rootPath(dir) {
7 | return resolve(process.cwd(), dir);
8 | }
9 |
10 | const doFile = rootPath('package.json');
11 |
12 | const reg = /\s+("dependencies"|"devDependencies")\s*:\s*{[^\}]+\},/g;
13 |
14 | const originalJSON = fs.readFileSync(doFile).toString();
15 |
16 | const writeFile = originalJSON.replace(reg, '');
17 |
18 | fs.writeFileSync(doFile, writeFile);
19 |
20 | exec('npm publish', (err, stdout, stderr) => {
21 | if (err) {
22 | return console.log(err);
23 | }
24 | console.log(stderr);
25 | console.log(
26 | `✔ ${packageJSON.name}@${packageJSON.version}----------------发布成功`
27 | );
28 |
29 | fs.writeFileSync(doFile, originalJSON);
30 | });
31 |
--------------------------------------------------------------------------------
/src/H5/buildRouter.ts:
--------------------------------------------------------------------------------
1 | import {RoutesRule, Router, routesMapRule, totalNextRoute, hookToggle, navtoRule} from '../options/base';
2 | import {H5Config} from '../options/config';
3 | import {warn} from '../helpers/warn'
4 | import {getDataType, getRoutePath} from '../helpers/utils'
5 | import { onTriggerEachHook } from '../public/hooks';
6 |
7 | export function buildVueRoutes(router: Router, vueRouteMap:RoutesRule):RoutesRule {
8 | const {pathMap, finallyPathList} = (router.routesMap as routesMapRule);
9 | const vueRoutePathList:Array = Object.keys(vueRouteMap);
10 | for (let i = 0; i < vueRoutePathList.length; i++) {
11 | const path = vueRoutePathList[i];
12 | const myRoute:RoutesRule = pathMap[path];
13 | const vueRoute:RoutesRule = vueRouteMap[path];
14 | if (!myRoute) {
15 | warn(`${path} 路由地址在路由表中未找到,确定是否传递漏啦`, router, true);
16 | } else {
17 | const {finallyPath} = getRoutePath(myRoute, router);
18 | if (finallyPath instanceof Array) {
19 | throw new Error(`非 vueRouterDev 模式下,alias、aliasPath、path 无法提供数组类型! ${JSON.stringify(myRoute)}`);
20 | }
21 | if (myRoute.name != null) {
22 | vueRoute.name = myRoute.name;
23 | }
24 | const vuePath = vueRoute['path'];
25 | const vueAlias = vueRoute['alias'];
26 | delete vueRoute['alias'];
27 | vueRoute['path'] = (finallyPath as string);
28 | if (vuePath === '/' && vueAlias != null) {
29 | vueRoute['alias'] = vueAlias;
30 | vueRoute['path'] = vuePath;
31 | }
32 | const beforeEnter = myRoute.beforeEnter;
33 | if (beforeEnter) {
34 | vueRoute['beforeEnter'] = function(
35 | to:totalNextRoute,
36 | from: totalNextRoute,
37 | next:(rule?: navtoRule|false)=>void,
38 | ):void{
39 | onTriggerEachHook(to, from, router, hookToggle['enterHooks'], next)
40 | };
41 | }
42 | }
43 | }
44 | if (finallyPathList.includes('*')) {
45 | vueRouteMap['*'] = pathMap['*']
46 | }
47 | return vueRouteMap
48 | }
49 |
50 | export function buildVueRouter(router:Router, vueRouter:any, vueRouteMap:RoutesRule|RoutesRule[]) :void |never {
51 | let routes:RoutesRule[] = [];
52 | if (getDataType(vueRouteMap) === '[object Array]') {
53 | routes = (vueRouteMap as RoutesRule[]);
54 | } else {
55 | routes = Object.values(vueRouteMap);
56 | }
57 | const {scrollBehavior, fallback} = router.options.h5 as H5Config;
58 | const oldScrollBehavior = vueRouter.options.scrollBehavior;
59 | vueRouter.options.scrollBehavior = function proxyScrollBehavior(
60 | to:totalNextRoute,
61 | from:totalNextRoute,
62 | savedPosition:any
63 | ) {
64 | oldScrollBehavior && oldScrollBehavior(to, from, savedPosition);
65 | return (scrollBehavior as Function)(to, from, savedPosition)
66 | }
67 | vueRouter.fallback = fallback;
68 | // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
69 | const newVueRouter:any = new vueRouter.constructor({
70 | ...router.options.h5,
71 | base: vueRouter.options.base,
72 | mode: vueRouter.options.mode,
73 | routes
74 | });
75 | vueRouter.matcher = newVueRouter.matcher;
76 | }
77 |
--------------------------------------------------------------------------------
/src/H5/patch.ts:
--------------------------------------------------------------------------------
1 | import { removeSimpleValue } from '../helpers/utils';
2 | import { Router} from '../options/base';
3 |
4 | let [dynamicCacheName, __id__] = ['', ''];
5 |
6 | export const addKeepAliveInclude = function(
7 | router:Router
8 | ):void{
9 | // 【Fixe】 https://github.com/SilurianYang/uni-simple-router/issues/316 2021年12月10日14:30:13
10 | const app = getApp();
11 | const keepAliveInclude:Array = app.keepAliveInclude;
12 | if (router.runId === 0 && keepAliveInclude.length === 0) {
13 | __id__ = app.$route.params.__id__;
14 | dynamicCacheName = app.$route.meta.name;
15 | const cacheId = dynamicCacheName + '-' + __id__;
16 | app.keepAliveInclude.push(cacheId)
17 | } else {
18 | if (dynamicCacheName !== '') {
19 | const arrayCacheId = app.keepAliveInclude;
20 | for (let i = 0; i < arrayCacheId.length; i++) {
21 | const cacheId:string = arrayCacheId[i];
22 | const cacheIdReg = new RegExp(`${dynamicCacheName}-(\\d+)$`);
23 | const firstCacheId = `${dynamicCacheName}-${__id__}`;
24 | if (cacheIdReg.test(cacheId) && cacheId !== firstCacheId) {
25 | removeSimpleValue(arrayCacheId, firstCacheId);
26 | dynamicCacheName = '';
27 | break;
28 | }
29 | }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/H5/proxyHook.ts:
--------------------------------------------------------------------------------
1 | import {Router, proxyHookName, totalNextRoute, navtoRule} from '../options/base';
2 |
3 | export class MyArray extends Array {
4 | constructor(
5 | private router:Router,
6 | private vueEachArray:Array,
7 | private myEachHook:Function,
8 | private hookName:'beforeHooks'| 'afterHooks',
9 | ) {
10 | super();
11 | Object.setPrototypeOf(this, MyArray.prototype)
12 | }
13 | push(v:any):any {
14 | this.vueEachArray.push(v);
15 | const index = this.length;
16 | this[this.length] = (to: totalNextRoute, from: totalNextRoute, next:(rule?: navtoRule|false)=>void) => {
17 | if (index > 0) {
18 | this.vueEachArray[index](to, from, () => {
19 | next && next()
20 | });
21 | } else {
22 | this.myEachHook(to, from, (nextTo?:navtoRule|false) => {
23 | // Fixe https://github.com/SilurianYang/uni-simple-router/issues/241 2021年3月6日22:15:27
24 | // 目前不调用uni-app的守卫函数,因为会丢失页面栈信息
25 | if (nextTo === false) {
26 | next(false);
27 | } else {
28 | this.vueEachArray[index](to, from, (uniNextTo?:navtoRule|false) => {
29 | next(nextTo);
30 | })
31 | }
32 | }, this.router, true);
33 | }
34 | };
35 | }
36 | }
37 |
38 | export function proxyEachHook(router:Router, vueRouter:any):void {
39 | const hookList:Array<'beforeHooks'| 'afterHooks'> = ['beforeHooks', 'afterHooks'];
40 | for (let i = 0; i < hookList.length; i++) {
41 | const hookName = hookList[i];
42 | const myEachHook = router.lifeCycle[(hookName as proxyHookName)][0];
43 | if (myEachHook) {
44 | const vueEachArray:Array = vueRouter[hookName];
45 | vueRouter[hookName] = new MyArray(router, vueEachArray, myEachHook, hookName);
46 | }
47 | }
48 | }
49 | export function proxyH5Mount(router:Router):void {
50 | if (router.mount.length === 0) {
51 | if (router.options.h5?.vueRouterDev) {
52 | return
53 | }
54 | const uAgent = navigator.userAgent;
55 | const isIos = !!uAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
56 | if (isIos) {
57 | // 【Fixe】 https://github.com/SilurianYang/uni-simple-router/issues/109
58 | setTimeout(() => {
59 | const element = document.getElementsByTagName('uni-page');
60 | if (element.length > 0) {
61 | return false
62 | }
63 | window.location.reload();
64 | }, 0);
65 | }
66 | } else {
67 | const [{app}] = router.mount;
68 | app.$mount();
69 | router.mount = [];
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/app/appPatch.ts:
--------------------------------------------------------------------------------
1 | import { navtoRule, objectAny, Router, totalNextRoute } from '../options/base';
2 | import { AppConfig } from '../options/config';
3 |
4 | let quitBefore:number|null = null;
5 | let TABBAR:objectAny|null = null;
6 |
7 | export function registerLoddingPage(
8 | router:Router,
9 | ):void{
10 | if (router.options.APP?.registerLoadingPage) {
11 | const { loadingPageHook, loadingPageStyle } = router.options.APP as AppConfig; // 获取app所有配置
12 | const view = new plus.nativeObj.View('router-loadding', {
13 | top: '0px',
14 | left: '0px',
15 | height: '100%',
16 | width: '100%',
17 | ...(loadingPageStyle as Function)()
18 | });
19 | (loadingPageHook as Function)(view); // 触发等待页面生命周期
20 | }
21 | }
22 |
23 | export function runtimeQuit(
24 | title:string|undefined = '再按一次退出应用'
25 | ):void{
26 | const nowTime = +new Date();
27 | if (!quitBefore) {
28 | quitBefore = nowTime;
29 | uni.showToast({
30 | title,
31 | icon: 'none',
32 | position: 'bottom',
33 | duration: 1000
34 | });
35 | setTimeout(() => { quitBefore = null }, 1000);
36 | } else {
37 | if (nowTime - quitBefore < 1000) {
38 | plus.runtime.quit();
39 | }
40 | }
41 | }
42 |
43 | export function HomeNvueSwitchTab(
44 | router:Router,
45 | to:navtoRule,
46 | oldMethod:Function
47 | ):Promise {
48 | return new Promise((
49 | resolve:(value:boolean)=>void
50 | ) => {
51 | if (router.runId !== 0) {
52 | return resolve(false)
53 | }
54 | if (!(__uniConfig.tabBar && Array.isArray(__uniConfig.tabBar.list))) {
55 | return resolve(false)
56 | }
57 | // Fixe https://github.com/SilurianYang/uni-simple-router/issues/373 2022-4-3 19:40:59
58 | oldMethod({
59 | url: __uniConfig.entryPagePath,
60 | animationDuration:0,
61 | complete: () => resolve(true)
62 | });
63 | })
64 | }
65 |
66 | export function tabIndexSelect(
67 | to:totalNextRoute,
68 | from:totalNextRoute
69 | ):boolean {
70 | if (!(__uniConfig.tabBar && Array.isArray(__uniConfig.tabBar.list))) {
71 | return false
72 | }
73 | const tabBarList = __uniConfig.tabBar.list;
74 | const routes:Array = [];
75 | let activeIndex:number = 0;
76 | for (let i = 0; i < tabBarList.length; i++) {
77 | const route:totalNextRoute = tabBarList[i];
78 | if ('/' + route.pagePath === to.path || '/' + route.pagePath === from.path) {
79 | if (route.pagePath === from.path) {
80 | activeIndex = i;
81 | }
82 | routes.push(route);
83 | }
84 | if (routes.length === 2) {
85 | break
86 | }
87 | }
88 | if (routes.length !== 2) {
89 | return false
90 | }
91 | if (TABBAR == null) {
92 | TABBAR = uni.requireNativePlugin('uni-tabview')
93 | }
94 | (TABBAR as objectAny).switchSelect({
95 | index: activeIndex
96 | })
97 | return true
98 | }
99 |
--------------------------------------------------------------------------------
/src/applets/appletPatch.ts:
--------------------------------------------------------------------------------
1 | import { Router} from '../options/base';
2 |
3 | export function getEnterPath(
4 | vueVim:any,
5 | router:Router,
6 | ) :string {
7 | switch (router.options.platform) {
8 | case 'mp-alipay':
9 | case 'mp-weixin':
10 | case 'mp-toutiao':
11 | case 'mp-qq':
12 | return vueVim.$options.mpInstance.route;
13 | case 'mp-baidu':
14 | // 【Fixe】 https://github.com/SilurianYang/uni-simple-router/issues/251
15 | return vueVim.$options.mpInstance.is || vueVim.$options.mpInstance.pageinstance.route;
16 | }
17 | return vueVim.$options.mpInstance.route; // 这是暂时的 因为除了以上的小程序 其他没测试 先这样写
18 | }
19 |
--------------------------------------------------------------------------------
/src/component/link.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
86 |
--------------------------------------------------------------------------------
/src/global.d.ts:
--------------------------------------------------------------------------------
1 | declare var uni:any;
2 | declare var plus:any;
3 | declare var __uniConfig:any;
4 | declare var __uniRoutes:any;
5 | declare function getCurrentPages(isAll:boolean|undefined=false):any;
6 | declare function getApp(args?:{allowDefault: true}):any;
7 | declare var $npm_package_name:string;
8 | declare var $npm_package_version:string;
9 | declare var $npm_package_last_version:string;
--------------------------------------------------------------------------------
/src/helpers/config.ts:
--------------------------------------------------------------------------------
1 | import {err} from './warn'
2 | import { InstantiateConfig, LifeCycleConfig} from '../options/config'
3 | import { vueHookNameRule, proxyDepsRule } from '../options/base';
4 | import { parseQuery } from '../public/query';
5 |
6 | export const mpPlatformReg = '(^mp-weixin$)|(^mp-baidu$)|(^mp-alipay$)|(^mp-toutiao$)|(^mp-qq$)|(^mp-360$)' // 小程序下不能直接导出正则 需要重新组装成正则 不然bug一推 诡异
7 |
8 | export const baseConfig:InstantiateConfig = {
9 | h5: {
10 | paramsToQuery: false,
11 | vueRouterDev: false,
12 | vueNext: false,
13 | mode: 'hash',
14 | base: '/',
15 | linkActiveClass: 'router-link-active',
16 | linkExactActiveClass: 'router-link-exact-active',
17 | scrollBehavior: (to:any, from:any, savedPostion:Function) => ({ x: 0, y: 0 }),
18 | fallback: true
19 | },
20 | APP: {
21 | registerLoadingPage: true,
22 | loadingPageStyle: () => JSON.parse('{"backgroundColor":"#FFF"}'),
23 | loadingPageHook: (view:any) => { view.show(); },
24 | launchedHook: () => { plus.navigator.closeSplashscreen(); },
25 | animation: {}
26 | },
27 | applet: {
28 | animationDuration: 300
29 | },
30 | beforeProxyHooks: {
31 | onLoad: ([options], next, router) => {
32 | next([parseQuery({query: options}, router)])
33 | }
34 | },
35 | platform: 'h5',
36 | keepUniOriginNav: false,
37 | debugger: false,
38 | routerBeforeEach: (to, from, next) => { next() },
39 | routerAfterEach: (to, from) => {},
40 | routerErrorEach: (error, router) => { router.$lockStatus = false; err(error, router, true); },
41 | detectBeforeLock: (router, to, navType) => {},
42 | routes: [
43 | {
44 | path: '/choose-location'
45 | },
46 | {
47 | path: '/open-location'
48 | },
49 | {
50 | path: '/preview-image'
51 | }
52 | ]
53 | }
54 |
55 | export const lifeCycle:LifeCycleConfig = {
56 | beforeHooks: [],
57 | afterHooks: [],
58 | routerBeforeHooks: [],
59 | routerAfterHooks: [],
60 | routerErrorHooks: []
61 | };
62 |
63 | export const proxyHookDeps:proxyDepsRule = {
64 | resetIndex: [], // 还原时执行的生命周期的索引
65 | hooks: {},
66 | options: {}
67 | }
68 |
69 | export const proxyHookName:Array = [
70 | 'onLaunch',
71 | 'onShow',
72 | 'onHide',
73 | 'onError',
74 | 'onInit',
75 | 'onLoad',
76 | 'onReady',
77 | 'onUnload',
78 | 'onResize',
79 | 'created',
80 | 'beforeMount',
81 | 'mounted',
82 | 'beforeDestroy',
83 | 'destroyed'
84 | ]
85 |
--------------------------------------------------------------------------------
/src/helpers/createRouteMap.ts:
--------------------------------------------------------------------------------
1 | import {RoutesRule, Router, routesMapRule} from '../options/base';
2 | import {H5Config} from '../options/config';
3 | import {warn} from './warn'
4 | import {getRoutePath} from './utils'
5 |
6 | export function createRouteMap(
7 | router: Router,
8 | routes: RoutesRule[],
9 | ): routesMapRule|never {
10 | const routesMap:routesMapRule = {
11 | finallyPathList: [],
12 | finallyPathMap: Object.create(null),
13 | aliasPathMap: Object.create(null),
14 | pathMap: Object.create(null),
15 | vueRouteMap: Object.create(null),
16 | nameMap: Object.create(null)
17 | }
18 | routes.forEach(route => {
19 | const { finallyPath, aliasPath, path} = getRoutePath(route, router);
20 | if (path == null) {
21 | throw new Error(`请提供一个完整的路由对象,包括以绝对路径开始的 ‘path’ 字符串 ${JSON.stringify(route)}`);
22 | }
23 | if (finallyPath instanceof Array) {
24 | if (!(router.options.h5 as H5Config).vueRouterDev && router.options.platform === 'h5') {
25 | throw new Error(`非 vueRouterDev 模式下,route.alias 目前无法提供数组类型! ${JSON.stringify(route)}`);
26 | }
27 | }
28 | const strFinallyPath = (finallyPath as string);
29 | const strAliasPath = (aliasPath as string);
30 | if (router.options.platform !== 'h5') {
31 | if (strFinallyPath.indexOf('/') !== 0 && path !== '*') {
32 | warn(`当前路由对象下,route:${JSON.stringify(route)} 是否缺少了前缀 ‘/’`, router, true);
33 | }
34 | }
35 | if (!routesMap.finallyPathMap[strFinallyPath]) {
36 | routesMap.finallyPathMap[strFinallyPath] = route;
37 | routesMap.aliasPathMap[strAliasPath] = route;
38 | routesMap.pathMap[path] = route;
39 | routesMap.finallyPathList.push(strFinallyPath);
40 | if (route.name != null) {
41 | routesMap.nameMap[route.name] = route;
42 | }
43 | }
44 | })
45 |
46 | return routesMap;
47 | }
48 |
--------------------------------------------------------------------------------
/src/helpers/lifeCycle.ts:
--------------------------------------------------------------------------------
1 | import { navtoRule, navErrorRule, Router, proxyHookName, guardHookRule, totalNextRoute, hookToggle} from '../options/base';
2 | import { LifeCycleConfig, InstantiateConfig} from '../options/config';
3 | import {onTriggerEachHook} from '../public/hooks'
4 |
5 | export function registerHook(list:Array, fn:Function):void {
6 | list[0] = fn;
7 | }
8 |
9 | export function registerRouterHooks(cycleHooks:T, options:InstantiateConfig):T {
10 | registerHook(cycleHooks.routerBeforeHooks, function(to:totalNextRoute, from: totalNextRoute, next:(rule?: navtoRule|false)=>void):void {
11 | (options.routerBeforeEach as Function)(to, from, next);
12 | })
13 | registerHook(cycleHooks.routerAfterHooks, function(to:totalNextRoute, from: totalNextRoute):void {
14 | (options.routerAfterEach as Function)(to, from);
15 | })
16 | registerHook(cycleHooks.routerErrorHooks, function(error:navErrorRule, router:Router):void {
17 | (options.routerErrorEach as Function)(error, router);
18 | })
19 | return cycleHooks;
20 | }
21 |
22 | export function registerEachHooks(router:Router, hookType:proxyHookName, userGuard:guardHookRule) {
23 | registerHook(router.lifeCycle[hookType], function(
24 | to:totalNextRoute,
25 | from: totalNextRoute,
26 | next:(rule?: navtoRule|false)=>void,
27 | router:Router,
28 | auto:boolean,
29 | ):void {
30 | if (auto) { // h5端 vue-router自动触发 非自己调用触发
31 | onTriggerEachHook(to, from, router, hookToggle[hookType], next)
32 | } else {
33 | userGuard(to, from, next)
34 | }
35 | })
36 | }
37 |
--------------------------------------------------------------------------------
/src/helpers/mixins.ts:
--------------------------------------------------------------------------------
1 | import { Router, routesMapRule, RoutesRule, pageTypeRule} from '../options/base';
2 | import {createRouteMap} from '../helpers/createRouteMap'
3 | import {buildVueRoutes, buildVueRouter} from '../H5/buildRouter'
4 | import {proxyEachHook} from '../H5/proxyHook'
5 | import {registerLoddingPage} from '../app/appPatch';
6 | import { proxyPageHook } from '../public/page';
7 | import { forceGuardEach } from '../public/methods';
8 | import { assertParentChild, voidFun } from './utils';
9 | import { getEnterPath } from '../applets/appletPatch';
10 | import { mpPlatformReg } from './config';
11 | import {beforeProxyHook} from '../public/beforeProxyHook'
12 |
13 | let registerRouter:boolean = false;
14 | let onloadProxyOk:boolean = false;
15 |
16 | const appletProxy:{
17 | app:boolean;
18 | page:string;
19 | } = {
20 | app: false,
21 | page: ''
22 | }
23 |
24 | export function getMixins(Vue:any, router: Router):{
25 | beforeCreate(this: any): void;
26 | } | {
27 | beforeCreate(): void;
28 | } | {
29 | onLaunch(): void;
30 | } {
31 | let platform = router.options.platform;
32 | if (new RegExp(mpPlatformReg, 'g').test(platform)) {
33 | platform = 'app-lets';
34 | }
35 | const toggleHooks = {
36 | h5: {
37 | beforeCreate(this: any): void {
38 | beforeProxyHook(this, router);
39 | if (this.$options.router) {
40 | router.$route = this.$options.router; // 挂载vue-router到路由对象下
41 | let vueRouteMap:RoutesRule[]|RoutesRule = [];
42 | if (router.options.h5?.vueRouterDev) {
43 | vueRouteMap = router.options.routes;
44 | } else {
45 | vueRouteMap = createRouteMap(router, this.$options.router.options.routes).finallyPathMap;
46 | (router.routesMap as routesMapRule).vueRouteMap = vueRouteMap;
47 | buildVueRoutes(router, vueRouteMap);
48 | }
49 | buildVueRouter(router, this.$options.router, vueRouteMap);
50 | proxyEachHook(router, this.$options.router);
51 | }
52 | }
53 | },
54 | 'app-plus': {
55 | beforeCreate(this: any): void {
56 | beforeProxyHook(this, router);
57 | if (!registerRouter) {
58 | registerRouter = true;
59 | proxyPageHook(this, router, 'app');
60 | registerLoddingPage(router);
61 | }
62 | }
63 | },
64 | 'app-lets': {
65 | beforeCreate(this: any): void {
66 | beforeProxyHook(this, router);
67 |
68 | // 保证这个函数不会被重写
69 | const pluginMark = $npm_package_name;
70 | voidFun(pluginMark);
71 |
72 | let isProxy:boolean = true;
73 | const pageType:pageTypeRule = this.$options.mpType;
74 |
75 | if (onloadProxyOk) {
76 | return
77 | }
78 |
79 | if (pageType === 'component') {
80 | isProxy = assertParentChild(appletProxy['page'], this);
81 | } else {
82 | if (pageType === 'page') {
83 | appletProxy[pageType] = getEnterPath(this, router);
84 | router.enterPath = appletProxy[pageType]; // 我不确定在不同端是否都是同样的变现?可能有的为非绝对路径?
85 | } else {
86 | appletProxy[pageType] = true;
87 | }
88 | }
89 | if (isProxy) {
90 | proxyPageHook(this, router, pageType);
91 | }
92 | },
93 | onLoad(this: any):void{
94 | // 保证这个函数不会被重写,否则必须在启动页写onLoad
95 | const pluginMark = $npm_package_name;
96 | voidFun(pluginMark);
97 |
98 | if (!onloadProxyOk && assertParentChild(appletProxy['page'], this)) {
99 | onloadProxyOk = true;
100 | forceGuardEach(router);
101 | }
102 | }
103 | }
104 | };
105 | return toggleHooks[(platform as 'h5'|'app-plus'|'app-lets')];
106 | }
107 | export function initMixins(Vue: any, router: Router) {
108 | const routesMap = createRouteMap(router, router.options.routes);
109 | router.routesMap = routesMap; // 挂载自身路由表到路由对象下
110 | // Vue.util.defineReactive(router, '_Route', createRoute(router, 19970806))
111 | Vue.mixin({
112 | ...getMixins(Vue, router)
113 | });
114 | }
115 |
--------------------------------------------------------------------------------
/src/helpers/warn.ts:
--------------------------------------------------------------------------------
1 |
2 | import {debuggerConfig, debuggerArrayConfig} from '../options/config'
3 | import {Router} from '../options/base'
4 |
5 | type callType='error'|'warn'|'log';
6 |
7 | export function isLog(type:callType, dev:debuggerConfig, errText:any, enforce:boolean = false):boolean {
8 | if (!enforce) {
9 | const isObject = dev.toString() === '[object Object]';
10 | if (dev === false) {
11 | return false
12 | } else if (isObject) {
13 | if ((dev as debuggerArrayConfig)[type] === false) {
14 | return false;
15 | }
16 | }
17 | }
18 | console[type](errText);
19 | return true;
20 | }
21 | export function err(errText:any, router:Router, enforce?:boolean):void {
22 | const dev = (router.options.debugger as debuggerConfig);
23 | isLog('error', dev, errText, enforce);
24 | }
25 |
26 | export function warn(errText:any, router:Router, enforce?:boolean):void {
27 | const dev = (router.options.debugger as debuggerConfig);
28 | isLog('warn', dev, errText, enforce);
29 | }
30 |
31 | export function log(errText:any, router:Router, enforce?:boolean):void {
32 | const dev = (router.options.debugger as debuggerConfig);
33 | isLog('log', dev, errText, enforce);
34 | }
35 | export function warnLock(errText:any):void {
36 | console.warn(errText);
37 | }
38 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from './options/base'
2 | export * from './options/config'
3 | export * from './helpers/utils'
4 |
5 | export {
6 | runtimeQuit
7 | } from './app/appPatch'
8 |
9 | export {
10 | RouterMount,
11 | createRouter
12 | } from './public/router'
13 |
14 | const version = $npm_package_version;
15 | if (/[A-Z]/g.test(version)) {
16 | console.warn(`【${$npm_package_name.toLocaleLowerCase()} 提示】:当前版本 ${version.toLocaleLowerCase()} 此版本为测试版。有BUG请退回正式版,线上正式版本:${$npm_package_last_version}`)
17 | }
18 |
--------------------------------------------------------------------------------
/src/options/base.ts:
--------------------------------------------------------------------------------
1 | import {InstantiateConfig, LifeCycleConfig} from '../options/config';
2 |
3 | export enum hookToggle{
4 | 'beforeHooks'='beforeEach',
5 | 'afterHooks'='afterEach',
6 | 'enterHooks'='beforeEnter'
7 | }
8 | export enum navtypeToggle{
9 | 'push'='navigateTo',
10 | 'replace'='redirectTo',
11 | 'replaceAll'='reLaunch',
12 | 'pushTab'='switchTab',
13 | 'back'='navigateBack'
14 | }
15 | export enum rewriteMethodToggle{
16 | 'navigateTo'='push',
17 | 'navigate'='push',
18 | 'redirectTo'='replace',
19 | 'reLaunch'='replaceAll',
20 | 'switchTab'='pushTab',
21 | 'navigateBack'='back',
22 | }
23 | export type proxyDepsRule={
24 | resetIndex:Array;
25 | hooks: {
26 | [key: number]:{
27 | proxyHook:()=>void;
28 | callHook:(enterPath:string)=>void;
29 | resetHook: ()=>void
30 | }
31 | };
32 | options: {[key: number]: Array;};
33 | };
34 | export type backTypeRule='backbutton'|'navigateBack'
35 | export type pageTypeRule='app'|'page'|'component';
36 | export type vueHookNameRule='onLaunch'|'onShow'|'onHide'|'onError'|'onInit'|'onLoad'|'onReady'|'onUnload'|'onResize'|'created'|'beforeMount'|'mounted'|'beforeDestroy'|'destroyed'
37 | export type reNavMethodRule='navigateTo'|'redirectTo'|'reLaunch'|'switchTab';
38 | export type reNotNavMethodRule='navigateBack';
39 | export type reloadNavRule=totalNextRoute | false | undefined|string;
40 | export type hookListRule=Array<(router:Router, to:totalNextRoute, from: totalNextRoute, toRoute:RoutesRule,next:Function)=>void>
41 | export type guardHookRule=(to: totalNextRoute, from: totalNextRoute, next:(rule?: navtoRule|false)=>void)=>void;
42 | export type navRuleStatus= 0|1|2|3; //0: next(false) 1:next(unknownType) 2:加锁状态,禁止跳转 3:在获取页面栈的时候,页面栈不够level获取
43 | export type proxyHookName='beforeHooks'|'afterHooks';
44 | export type navMethodRule = Promise;
45 | export type objectAny={[propName: string]: any;};
46 | export type NAVTYPE = 'push' | 'replace' | 'replaceAll' | 'pushTab'|'back';
47 | export type startAnimationType =
48 | | 'slide-in-right'
49 | | 'slide-in-left'
50 | | 'slide-in-top'
51 | | 'slide-in-bottom'
52 | | 'pop-in'
53 | | 'fade-in'
54 | | 'zoom-out'
55 | | 'zoom-fade-out'
56 | | 'none';
57 | export type endAnimationType =
58 | | 'slide-out-right'
59 | | 'slide-out-left'
60 | | 'slide-out-top'
61 | | 'slide-out-bottom'
62 | | 'pop-out'
63 | | 'fade-out'
64 | | 'zoom-in'
65 | | 'zoom-fade-in'
66 | | 'none';
67 |
68 | export type vueOptionRule = {
69 | [propName in vueHookNameRule]: Array | undefined;
70 | };
71 |
72 | // 跳转api时,传递的跳转规则
73 | export interface navtoRule {
74 | NAVTYPE?: NAVTYPE; // 跳转类型 v1.1.0+
75 | path?: string; // 跳转路径 绝对路径
76 | name?: string | undefined; // 跳转路径名称
77 | query?: objectAny; // 跳转使用path时 query包含需要传递的参数
78 | params?: objectAny; // 跳转使用name时 params包含需要传递的参数
79 | animationType?: startAnimationType|endAnimationType;
80 | animationDuration?: number;
81 | events?: objectAny;
82 | success?: Function;
83 | fail?: Function;
84 | complete?: Function;
85 | }
86 | // h5 next管道函数中传递的from及to对象
87 | export interface h5NextRule {
88 | fullPath?: string | undefined;
89 | hash?: string | undefined;
90 | matched?: Array