kdu-router 3.0.0 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/dist/kdu-router.common.js +128 -68
- package/dist/kdu-router.esm.browser.js +2632 -0
- package/dist/kdu-router.esm.browser.min.js +11 -0
- package/dist/kdu-router.esm.js +128 -68
- package/dist/kdu-router.js +128 -68
- package/dist/kdu-router.min.js +8 -3
- package/package.json +43 -26
- package/src/create-matcher.js +200 -0
- package/src/create-route-map.js +171 -0
- package/src/index.js +247 -0
- package/src/install.js +52 -0
- package/types/kdu.d.ts +3 -3
- package/types/router.d.ts +9 -8
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* kdu-router v3.0.7
|
|
3
|
+
* (c) 2022 NKDuy
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
/*!
|
|
7
|
+
* kdu-router v3.0.7
|
|
8
|
+
* (c) 2022 NKDuy
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
function t(t){return Object.prototype.toString.call(t).indexOf("Error")>-1}function e(t,e){for(const n in e)t[n]=e[n];return t}var n={name:"RouterView",functional:!0,props:{name:{type:String,default:"default"}},render(t,{props:n,children:r,parent:o,data:i}){i.routerView=!0;const s=o.$createElement,a=n.name,c=o.$route,u=o._routerViewCache||(o._routerViewCache={});let h=0,p=!1;for(;o&&o._routerRoot!==o;){const t=o.$knode&&o.$knode.data;t&&(t.routerView&&h++,t.keepAlive&&o._inactive&&(p=!0)),o=o.$parent}if(i.routerViewDepth=h,p)return s(u[a],i,r);const l=c.matched[h];if(!l)return u[a]=null,s();const f=u[a]=l.components[a];i.registerRouteInstance=(t,e)=>{const n=l.instances[a];(e&&n!==t||!e&&n===t)&&(l.instances[a]=e)},(i.hook||(i.hook={})).prepatch=(t,e)=>{l.instances[a]=e.componentInstance},i.hook.init=t=>{t.data.keepAlive&&t.componentInstance&&t.componentInstance!==l.instances[a]&&(l.instances[a]=t.componentInstance)};let d=i.props=function(t,e){switch(typeof e){case"undefined":return;case"object":return e;case"function":return e(t);case"boolean":return e?t.params:void 0}}(c,l.props&&l.props[a]);if(d){d=i.props=e({},d);const t=i.attrs=i.attrs||{};for(const e in d)f.props&&e in f.props||(t[e]=d[e],delete d[e])}return s(f,i,r)}};const r=/[!'()*]/g,o=t=>"%"+t.charCodeAt(0).toString(16),i=/%2C/g,s=t=>encodeURIComponent(t).replace(r,o).replace(i,","),a=decodeURIComponent;function c(t){const e={};return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(t=>{const n=t.replace(/\+/g," ").split("="),r=a(n.shift()),o=n.length>0?a(n.join("=")):null;void 0===e[r]?e[r]=o:Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]}),e):e}function u(t){const e=t?Object.keys(t).map(e=>{const n=t[e];if(void 0===n)return"";if(null===n)return s(e);if(Array.isArray(n)){const t=[];return n.forEach(n=>{void 0!==n&&(null===n?t.push(s(e)):t.push(s(e)+"="+s(n)))}),t.join("&")}return s(e)+"="+s(n)}).filter(t=>t.length>0).join("&"):null;return e?"?"+e:""}const h=/\/?$/;function p(t,e,n,r){const o=r&&r.options.stringifyQuery;let i=e.query||{};try{i=l(i)}catch(t){}const s={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:i,params:e.params||{},fullPath:y(e,o),matched:t?d(t):[]};return n&&(s.redirectedFrom=y(n,o)),Object.freeze(s)}function l(t){if(Array.isArray(t))return t.map(l);if(t&&"object"==typeof t){const e={};for(const n in t)e[n]=l(t[n]);return e}return t}const f=p(null,{path:"/"});function d(t){const e=[];for(;t;)e.unshift(t),t=t.parent;return e}function y({path:t,query:e={},hash:n=""},r){return(t||"/")+(r||u)(e)+n}function m(t,e){return e===f?t===e:!!e&&(t.path&&e.path?t.path.replace(h,"")===e.path.replace(h,"")&&t.hash===e.hash&&g(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&g(t.query,e.query)&&g(t.params,e.params)))}function g(t={},e={}){if(!t||!e)return t===e;const n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every(n=>{const r=t[n],o=e[n];return"object"==typeof r&&"object"==typeof o?g(r,o):String(r)===String(o)})}var w={name:"RouterLink",props:{to:{type:[String,Object],required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String,exactActiveClass:String,event:{type:[String,Array],default:"click"}},render(t){const n=this.$router,r=this.$route,{location:o,route:i,href:s}=n.resolve(this.to,r,this.append),a={},c=n.options.linkActiveClass,u=n.options.linkExactActiveClass,l=null==c?"router-link-active":c,f=null==u?"router-link-exact-active":u,d=null==this.activeClass?l:this.activeClass,y=null==this.exactActiveClass?f:this.exactActiveClass,g=o.path?p(null,o,null,n):i;a[y]=m(r,g),a[d]=this.exact?a[y]:function(t,e){return 0===t.path.replace(h,"/").indexOf(e.path.replace(h,"/"))&&(!e.hash||t.hash===e.hash)&&function(t,e){for(const n in e)if(!(n in t))return!1;return!0}(t.query,e.query)}(r,g);const w=t=>{b(t)&&(this.replace?n.replace(o):n.push(o))},v={click:b};Array.isArray(this.event)?this.event.forEach(t=>{v[t]=w}):v[this.event]=w;const x={class:a};if("a"===this.tag)x.on=v,x.attrs={href:s};else{const t=function t(e){if(e){let n;for(let r=0;r<e.length;r++){if(n=e[r],"a"===n.tag)return n;if(n.children&&(n=t(n.children)))return n}}}(this.$slots.default);if(t){t.isStatic=!1;(t.data=e({},t.data)).on=v;(t.data.attrs=e({},t.data.attrs)).href=s}else x.on=v}return t(this.tag,x,this.$slots.default)}};function b(t){if(!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey||t.defaultPrevented||void 0!==t.button&&0!==t.button)){if(t.currentTarget&&t.currentTarget.getAttribute){const e=t.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(e))return}return t.preventDefault&&t.preventDefault(),!0}}let v;const x="undefined"!=typeof window;function k(t,e,n){const r=t.charAt(0);if("/"===r)return t;if("?"===r||"#"===r)return e+t;const o=e.split("/");n&&o[o.length-1]||o.pop();const i=t.replace(/^\//,"").split("/");for(let t=0;t<i.length;t++){const e=i[t];".."===e?o.pop():"."!==e&&o.push(e)}return""!==o[0]&&o.unshift(""),o.join("/")}function R(t){return t.replace(/\/\//g,"/")}var E=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},O=B,A=S,C=function(t,e){return L(S(t,e),e)},$=L,j=M,T=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function S(t,e){for(var n,r=[],o=0,i=0,s="",a=e&&e.delimiter||"/";null!=(n=T.exec(t));){var c=n[0],u=n[1],h=n.index;if(s+=t.slice(i,h),i=h+c.length,u)s+=u[1];else{var p=t[i],l=n[2],f=n[3],d=n[4],y=n[5],m=n[6],g=n[7];s&&(r.push(s),s="");var w=null!=l&&null!=p&&p!==l,b="+"===m||"*"===m,v="?"===m||"*"===m,x=n[2]||a,k=d||y;r.push({name:f||o++,prefix:l||"",delimiter:x,optional:v,repeat:b,partial:w,asterisk:!!g,pattern:k?U(k):g?".*":"[^"+q(x)+"]+?"})}}return i<t.length&&(s+=t.substr(i)),s&&r.push(s),r}function _(t){return encodeURI(t).replace(/[\/?#]/g,(function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()}))}function L(t,e){for(var n=new Array(t.length),r=0;r<t.length;r++)"object"==typeof t[r]&&(n[r]=new RegExp("^(?:"+t[r].pattern+")$",I(e)));return function(e,r){for(var o="",i=e||{},s=(r||{}).pretty?_:encodeURIComponent,a=0;a<t.length;a++){var c=t[a];if("string"!=typeof c){var u,h=i[c.name];if(null==h){if(c.optional){c.partial&&(o+=c.prefix);continue}throw new TypeError('Expected "'+c.name+'" to be defined')}if(E(h)){if(!c.repeat)throw new TypeError('Expected "'+c.name+'" to not repeat, but received `'+JSON.stringify(h)+"`");if(0===h.length){if(c.optional)continue;throw new TypeError('Expected "'+c.name+'" to not be empty')}for(var p=0;p<h.length;p++){if(u=s(h[p]),!n[a].test(u))throw new TypeError('Expected all "'+c.name+'" to match "'+c.pattern+'", but received `'+JSON.stringify(u)+"`");o+=(0===p?c.prefix:c.delimiter)+u}}else{if(u=c.asterisk?encodeURI(h).replace(/[?#]/g,(function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})):s(h),!n[a].test(u))throw new TypeError('Expected "'+c.name+'" to match "'+c.pattern+'", but received "'+u+'"');o+=c.prefix+u}}else o+=c}return o}}function q(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function U(t){return t.replace(/([=!:$\/()])/g,"\\$1")}function P(t,e){return t.keys=e,t}function I(t){return t&&t.sensitive?"":"i"}function M(t,e,n){E(e)||(n=e||n,e=[]);for(var r=(n=n||{}).strict,o=!1!==n.end,i="",s=0;s<t.length;s++){var a=t[s];if("string"==typeof a)i+=q(a);else{var c=q(a.prefix),u="(?:"+a.pattern+")";e.push(a),a.repeat&&(u+="(?:"+c+u+")*"),i+=u=a.optional?a.partial?c+"("+u+")?":"(?:"+c+"("+u+"))?":c+"("+u+")"}}var h=q(n.delimiter||"/"),p=i.slice(-h.length)===h;return r||(i=(p?i.slice(0,-h.length):i)+"(?:"+h+"(?=$))?"),i+=o?"$":r&&p?"":"(?="+h+"|$)",P(new RegExp("^"+i,I(n)),e)}function B(t,e,n){return E(e)||(n=e||n,e=[]),n=n||{},t instanceof RegExp?function(t,e){var n=t.source.match(/\((?!\?)/g);if(n)for(var r=0;r<n.length;r++)e.push({name:r,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return P(t,e)}(t,e):E(t)?function(t,e,n){for(var r=[],o=0;o<t.length;o++)r.push(B(t[o],e,n).source);return P(new RegExp("(?:"+r.join("|")+")",I(n)),e)}(t,e,n):function(t,e,n){return M(S(t,n),e,n)}(t,e,n)}O.parse=A,O.compile=C,O.tokensToFunction=$,O.tokensToRegExp=j;const H=Object.create(null);function z(t,e,n){e=e||{};try{const n=H[t]||(H[t]=O.compile(t));return e.pathMatch&&(e[0]=e.pathMatch),n(e,{pretty:!0})}catch(t){return""}finally{delete e[0]}}function K(t,e,n,r){const o=e||[],i=n||Object.create(null),s=r||Object.create(null);t.forEach(t=>{!function t(e,n,r,o,i,s){const{path:a,name:c}=o,u=o.pathToRegexpOptions||{},h=function(t,e,n){n||(t=t.replace(/\/$/,""));return"/"===t[0]||null==e?t:R(`${e.path}/${t}`)}(a,i,u.strict);"boolean"==typeof o.caseSensitive&&(u.sensitive=o.caseSensitive);const p={path:h,regex:V(h,u),components:o.components||{default:o.component},instances:{},name:c,parent:i,matchAs:s,redirect:o.redirect,beforeEnter:o.beforeEnter,meta:o.meta||{},props:null==o.props?{}:o.components?o.props:{default:o.props}};o.children&&o.children.forEach(o=>{const i=s?R(`${s}/${o.path}`):void 0;t(e,n,r,o,p,i)});if(void 0!==o.alias){(Array.isArray(o.alias)?o.alias:[o.alias]).forEach(s=>{const a={path:s,children:o.children};t(e,n,r,a,i,p.path||"/")})}n[p.path]||(e.push(p.path),n[p.path]=p);c&&(r[c]||(r[c]=p))}(o,i,s,t)});for(let t=0,e=o.length;t<e;t++)"*"===o[t]&&(o.push(o.splice(t,1)[0]),e--,t--);return{pathList:o,pathMap:i,nameMap:s}}function V(t,e){return O(t,[],e)}function D(t,n,r,o){let i="string"==typeof t?{path:t}:t;if(i._normalized)return i;if(i.name)return e({},t);if(!i.path&&i.params&&n){i=e({},i),i._normalized=!0;const t=e(e({},n.params),i.params);if(n.name)i.name=n.name,i.params=t;else if(n.matched.length){const e=n.matched[n.matched.length-1].path;i.path=z(e,t,n.path)}return i}const s=function(t){let e="",n="";const r=t.indexOf("#");r>=0&&(e=t.slice(r),t=t.slice(0,r));const o=t.indexOf("?");return o>=0&&(n=t.slice(o+1),t=t.slice(0,o)),{path:t,query:n,hash:e}}(i.path||""),a=n&&n.path||"/",u=s.path?k(s.path,a,r||i.append):a,h=function(t,e={},n){const r=n||c;let o;try{o=r(t||"")}catch(t){o={}}for(const t in e)o[t]=e[t];return o}(s.query,i.query,o&&o.options.parseQuery);let p=i.hash||s.hash;return p&&"#"!==p.charAt(0)&&(p="#"+p),{_normalized:!0,path:u,query:h,hash:p}}function F(t,e){const{pathList:n,pathMap:r,nameMap:o}=K(t);function i(t,i,s){const c=D(t,i,!1,e),{name:u}=c;if(u){const t=o[u];if(!t)return a(null,c);const e=t.regex.keys.filter(t=>!t.optional).map(t=>t.name);if("object"!=typeof c.params&&(c.params={}),i&&"object"==typeof i.params)for(const t in i.params)!(t in c.params)&&e.indexOf(t)>-1&&(c.params[t]=i.params[t]);return c.path=z(t.path,c.params),a(t,c,s)}if(c.path){c.params={};for(let t=0;t<n.length;t++){const e=n[t],o=r[e];if(J(o.regex,c.path,c.params))return a(o,c,s)}}return a(null,c)}function s(t,n){const r=t.redirect;let s="function"==typeof r?r(p(t,n,null,e)):r;if("string"==typeof s&&(s={path:s}),!s||"object"!=typeof s)return a(null,n);const c=s,{name:u,path:h}=c;let{query:l,hash:f,params:d}=n;if(l=c.hasOwnProperty("query")?c.query:l,f=c.hasOwnProperty("hash")?c.hash:f,d=c.hasOwnProperty("params")?c.params:d,u){o[u];return i({_normalized:!0,name:u,query:l,hash:f,params:d},void 0,n)}if(h){const e=function(t,e){return k(t,e.parent?e.parent.path:"/",!0)}(h,t);return i({_normalized:!0,path:z(e,d),query:l,hash:f},void 0,n)}return a(null,n)}function a(t,n,r){return t&&t.redirect?s(t,r||n):t&&t.matchAs?function(t,e,n){const r=i({_normalized:!0,path:z(n,e.params)});if(r){const t=r.matched,n=t[t.length-1];return e.params=r.params,a(n,e)}return a(null,e)}(0,n,t.matchAs):p(t,n,r,e)}return{match:i,addRoutes:function(t){K(t,n,r,o)}}}function J(t,e,n){const r=e.match(t);if(!r)return!1;if(!n)return!0;for(let e=1,o=r.length;e<o;++e){const o=t.keys[e-1],i="string"==typeof r[e]?decodeURIComponent(r[e]):r[e];o&&(n[o.name||"pathMatch"]=i)}return!0}const N=Object.create(null);function Q(){const t=window.location.protocol+"//"+window.location.host,e=window.location.href.replace(t,"");window.history.replaceState({key:it()},"",e),window.addEventListener("popstate",t=>{var e;Y(),t.state&&t.state.key&&(e=t.state.key,rt=e)})}function X(t,e,n,r){if(!t.app)return;const o=t.options.scrollBehavior;o&&t.app.$nextTick(()=>{const i=function(){const t=it();if(t)return N[t]}(),s=o.call(t,e,n,r?i:null);s&&("function"==typeof s.then?s.then(t=>{tt(t,i)}).catch(t=>{}):tt(s,i))})}function Y(){const t=it();t&&(N[t]={x:window.pageXOffset,y:window.pageYOffset})}function W(t){return Z(t.x)||Z(t.y)}function G(t){return{x:Z(t.x)?t.x:window.pageXOffset,y:Z(t.y)?t.y:window.pageYOffset}}function Z(t){return"number"==typeof t}function tt(t,e){const n="object"==typeof t;if(n&&"string"==typeof t.selector){const n=document.querySelector(t.selector);if(n){let o=t.offset&&"object"==typeof t.offset?t.offset:{};o={x:Z((r=o).x)?r.x:0,y:Z(r.y)?r.y:0},e=function(t,e){const n=document.documentElement.getBoundingClientRect(),r=t.getBoundingClientRect();return{x:r.left-n.left-e.x,y:r.top-n.top-e.y}}(n,o)}else W(t)&&(e=G(t))}else n&&W(t)&&(e=G(t));var r;e&&window.scrollTo(e.x,e.y)}const et=x&&function(){const t=window.navigator.userAgent;return(-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone"))&&(window.history&&"pushState"in window.history)}(),nt=x&&window.performance&&window.performance.now?window.performance:Date;let rt=ot();function ot(){return nt.now().toFixed(3)}function it(){return rt}function st(t,e){Y();const n=window.history;try{e?n.replaceState({key:rt},"",t):(rt=ot(),n.pushState({key:rt},"",t))}catch(n){window.location[e?"replace":"assign"](t)}}function at(t){st(t,!0)}function ct(t,e,n){const r=o=>{o>=t.length?n():t[o]?e(t[o],()=>{r(o+1)}):r(o+1)};r(0)}function ut(e){return(n,r,o)=>{let i=!1,s=0,a=null;ht(e,(e,n,r,c)=>{if("function"==typeof e&&void 0===e.cid){i=!0,s++;const n=ft(t=>{var n;((n=t).__esModule||lt&&"Module"===n[Symbol.toStringTag])&&(t=t.default),e.resolved="function"==typeof t?t:v.extend(t),r.components[c]=t,s--,s<=0&&o()}),u=ft(e=>{const n=`Failed to resolve async component ${c}: ${e}`;a||(a=t(e)?e:new Error(n),o(a))});let h;try{h=e(n,u)}catch(t){u(t)}if(h)if("function"==typeof h.then)h.then(n,u);else{const t=h.component;t&&"function"==typeof t.then&&t.then(n,u)}}}),i||o()}}function ht(t,e){return pt(t.map(t=>Object.keys(t.components).map(n=>e(t.components[n],t.instances[n],t,n))))}function pt(t){return Array.prototype.concat.apply([],t)}const lt="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag;function ft(t){let e=!1;return function(...n){if(!e)return e=!0,t.apply(this,n)}}class dt{constructor(t,e){this.router=t,this.base=function(t){if(!t)if(x){const e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";"/"!==t.charAt(0)&&(t="/"+t);return t.replace(/\/$/,"")}(e),this.current=f,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[]}listen(t){this.cb=t}onReady(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))}onError(t){this.errorCbs.push(t)}transitionTo(t,e,n){const r=this.router.match(t,this.current);this.confirmTransition(r,()=>{this.updateRoute(r),e&&e(r),this.ensureURL(),this.ready||(this.ready=!0,this.readyCbs.forEach(t=>{t(r)}))},t=>{n&&n(t),t&&!this.ready&&(this.ready=!0,this.readyErrorCbs.forEach(e=>{e(t)}))})}confirmTransition(e,n,r){const o=this.current,i=e=>{t(e)&&(this.errorCbs.length?this.errorCbs.forEach(t=>{t(e)}):console.error(e)),r&&r(e)};if(m(e,o)&&e.matched.length===o.matched.length)return this.ensureURL(),i();const{updated:s,deactivated:a,activated:c}=function(t,e){let n;const r=Math.max(t.length,e.length);for(n=0;n<r&&t[n]===e[n];n++);return{updated:e.slice(0,n),activated:e.slice(n),deactivated:t.slice(n)}}(this.current.matched,e.matched),u=[].concat(function(t){return yt(t,"beforeRouteLeave",mt,!0)}(a),this.router.beforeHooks,function(t){return yt(t,"beforeRouteUpdate",mt)}(s),c.map(t=>t.beforeEnter),ut(c));this.pending=e;const h=(n,r)=>{if(this.pending!==e)return i();try{n(e,o,e=>{!1===e||t(e)?(this.ensureURL(!0),i(e)):"string"==typeof e||"object"==typeof e&&("string"==typeof e.path||"string"==typeof e.name)?(i(),"object"==typeof e&&e.replace?this.replace(e):this.push(e)):r(e)})}catch(t){i(t)}};ct(u,h,()=>{const t=[];ct(function(t,e,n){return yt(t,"beforeRouteEnter",(t,r,o,i)=>function(t,e,n,r,o){return function(i,s,a){return t(i,s,t=>{"function"==typeof t&&r.push(()=>{!function t(e,n,r,o){n[r]&&!n[r]._isBeingDestroyed?e(n[r]):o()&&setTimeout(()=>{t(e,n,r,o)},16)}(t,e.instances,n,o)}),a(t)})}}(t,o,i,e,n))}(c,t,()=>this.current===e).concat(this.router.resolveHooks),h,()=>{if(this.pending!==e)return i();this.pending=null,n(e),this.router.app&&this.router.app.$nextTick(()=>{t.forEach(t=>{t()})})})})}updateRoute(t){const e=this.current;this.current=t,this.cb&&this.cb(t),this.router.afterHooks.forEach(n=>{n&&n(t,e)})}}function yt(t,e,n,r){const o=ht(t,(t,r,o,i)=>{const s=function(t,e){"function"!=typeof t&&(t=v.extend(t));return t.options[e]}(t,e);if(s)return Array.isArray(s)?s.map(t=>n(t,r,o,i)):n(s,r,o,i)});return pt(r?o.reverse():o)}function mt(t,e){if(e)return function(){return t.apply(e,arguments)}}class gt extends dt{constructor(t,e){super(t,e);const n=t.options.scrollBehavior,r=et&&n;r&&Q();const o=wt(this.base);window.addEventListener("popstate",e=>{const n=this.current,i=wt(this.base);this.current===f&&i===o||this.transitionTo(i,e=>{r&&X(t,e,n,!0)})})}go(t){window.history.go(t)}push(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{st(R(this.base+t.fullPath)),X(this.router,t,r,!1),e&&e(t)},n)}replace(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{at(R(this.base+t.fullPath)),X(this.router,t,r,!1),e&&e(t)},n)}ensureURL(t){if(wt(this.base)!==this.current.fullPath){const e=R(this.base+this.current.fullPath);t?st(e):at(e)}}getCurrentLocation(){return wt(this.base)}}function wt(t){let e=decodeURI(window.location.pathname);return t&&0===e.indexOf(t)&&(e=e.slice(t.length)),(e||"/")+window.location.search+window.location.hash}class bt extends dt{constructor(t,e,n){super(t,e),n&&function(t){const e=wt(t);if(!/^\/#/.test(e))return window.location.replace(R(t+"/#"+e)),!0}(this.base)||vt()}setupListeners(){const t=this.router.options.scrollBehavior,e=et&&t;e&&Q(),window.addEventListener(et?"popstate":"hashchange",()=>{const t=this.current;vt()&&this.transitionTo(xt(),n=>{e&&X(this.router,n,t,!0),et||Et(n.fullPath)})})}push(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{Rt(t.fullPath),X(this.router,t,r,!1),e&&e(t)},n)}replace(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{Et(t.fullPath),X(this.router,t,r,!1),e&&e(t)},n)}go(t){window.history.go(t)}ensureURL(t){const e=this.current.fullPath;xt()!==e&&(t?Rt(e):Et(e))}getCurrentLocation(){return xt()}}function vt(){const t=xt();return"/"===t.charAt(0)||(Et("/"+t),!1)}function xt(){let t=window.location.href;const e=t.indexOf("#");if(e<0)return"";t=t.slice(e+1);const n=t.indexOf("?");if(n<0){const e=t.indexOf("#");t=e>-1?decodeURI(t.slice(0,e))+t.slice(e):decodeURI(t)}else n>-1&&(t=decodeURI(t.slice(0,n))+t.slice(n));return t}function kt(t){const e=window.location.href,n=e.indexOf("#");return`${n>=0?e.slice(0,n):e}#${t}`}function Rt(t){et?st(kt(t)):window.location.hash=t}function Et(t){et?at(kt(t)):window.location.replace(kt(t))}class Ot extends dt{constructor(t,e){super(t,e),this.stack=[],this.index=-1}push(t,e,n){this.transitionTo(t,t=>{this.stack=this.stack.slice(0,this.index+1).concat(t),this.index++,e&&e(t)},n)}replace(t,e,n){this.transitionTo(t,t=>{this.stack=this.stack.slice(0,this.index).concat(t),e&&e(t)},n)}go(t){const e=this.index+t;if(e<0||e>=this.stack.length)return;const n=this.stack[e];this.confirmTransition(n,()=>{this.index=e,this.updateRoute(n)})}getCurrentLocation(){const t=this.stack[this.stack.length-1];return t?t.fullPath:"/"}ensureURL(){}}class At{constructor(t={}){this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=F(t.routes||[],this);let e=t.mode||"hash";switch(this.fallback="history"===e&&!et&&!1!==t.fallback,this.fallback&&(e="hash"),x||(e="abstract"),this.mode=e,e){case"history":this.history=new gt(this,t.base);break;case"hash":this.history=new bt(this,t.base,this.fallback);break;case"abstract":this.history=new Ot(this,t.base)}}match(t,e,n){return this.matcher.match(t,e,n)}get currentRoute(){return this.history&&this.history.current}init(t){if(this.apps.push(t),t.$once("hook:destroyed",()=>{const e=this.apps.indexOf(t);e>-1&&this.apps.splice(e,1),this.app===t&&(this.app=this.apps[0]||null)}),this.app)return;this.app=t;const e=this.history;if(e instanceof gt)e.transitionTo(e.getCurrentLocation());else if(e instanceof bt){const t=()=>{e.setupListeners()};e.transitionTo(e.getCurrentLocation(),t,t)}e.listen(t=>{this.apps.forEach(e=>{e._route=t})})}beforeEach(t){return Ct(this.beforeHooks,t)}beforeResolve(t){return Ct(this.resolveHooks,t)}afterEach(t){return Ct(this.afterHooks,t)}onReady(t,e){this.history.onReady(t,e)}onError(t){this.history.onError(t)}push(t,e,n){this.history.push(t,e,n)}replace(t,e,n){this.history.replace(t,e,n)}go(t){this.history.go(t)}back(){this.go(-1)}forward(){this.go(1)}getMatchedComponents(t){const e=t?t.matched?t:this.resolve(t).route:this.currentRoute;return e?[].concat.apply([],e.matched.map(t=>Object.keys(t.components).map(e=>t.components[e]))):[]}resolve(t,e,n){const r=D(t,e=e||this.history.current,n,this),o=this.match(r,e),i=o.redirectedFrom||o.fullPath;return{location:r,route:o,href:function(t,e,n){var r="hash"===n?"#"+e:e;return t?R(t+"/"+r):r}(this.history.base,i,this.mode),normalizedTo:r,resolved:o}}addRoutes(t){this.matcher.addRoutes(t),this.history.current!==f&&this.history.transitionTo(this.history.getCurrentLocation())}}function Ct(t,e){return t.push(e),()=>{const n=t.indexOf(e);n>-1&&t.splice(n,1)}}At.install=function t(e){if(t.installed&&v===e)return;t.installed=!0,v=e;const r=t=>void 0!==t,o=(t,e)=>{let n=t.$options._parentKnode;r(n)&&r(n=n.data)&&r(n=n.registerRouteInstance)&&n(t,e)};e.mixin({beforeCreate(){r(this.$options.router)?(this._routerRoot=this,this._router=this.$options.router,this._router.init(this),e.util.defineReactive(this,"_route",this._router.history.current)):this._routerRoot=this.$parent&&this.$parent._routerRoot||this,o(this,this)},destroyed(){o(this)}}),Object.defineProperty(e.prototype,"$router",{get(){return this._routerRoot._router}}),Object.defineProperty(e.prototype,"$route",{get(){return this._routerRoot._route}}),e.component("RouterView",n),e.component("RouterLink",w);const i=e.config.optionMergeStrategies;i.beforeRouteEnter=i.beforeRouteLeave=i.beforeRouteUpdate=i.created},At.version="3.0.7",x&&window.Kdu&&window.Kdu.use(At);export default At;
|
package/dist/kdu-router.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
* kdu-router v3.0.
|
|
1
|
+
/*!
|
|
2
|
+
* kdu-router v3.0.7
|
|
3
3
|
* (c) 2022 NKDuy
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -21,8 +21,15 @@ function isError (err) {
|
|
|
21
21
|
return Object.prototype.toString.call(err).indexOf('Error') > -1
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
function extend (a, b) {
|
|
25
|
+
for (var key in b) {
|
|
26
|
+
a[key] = b[key];
|
|
27
|
+
}
|
|
28
|
+
return a
|
|
29
|
+
}
|
|
30
|
+
|
|
24
31
|
var View = {
|
|
25
|
-
name: '
|
|
32
|
+
name: 'RouterView',
|
|
26
33
|
functional: true,
|
|
27
34
|
props: {
|
|
28
35
|
name: {
|
|
@@ -36,6 +43,7 @@ var View = {
|
|
|
36
43
|
var parent = ref.parent;
|
|
37
44
|
var data = ref.data;
|
|
38
45
|
|
|
46
|
+
// used by devtools to display a router-view badge
|
|
39
47
|
data.routerView = true;
|
|
40
48
|
|
|
41
49
|
// directly use parent context's createElement() function
|
|
@@ -50,11 +58,14 @@ var View = {
|
|
|
50
58
|
var depth = 0;
|
|
51
59
|
var inactive = false;
|
|
52
60
|
while (parent && parent._routerRoot !== parent) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
var knodeData = parent.$knode && parent.$knode.data;
|
|
62
|
+
if (knodeData) {
|
|
63
|
+
if (knodeData.routerView) {
|
|
64
|
+
depth++;
|
|
65
|
+
}
|
|
66
|
+
if (knodeData.keepAlive && parent._inactive) {
|
|
67
|
+
inactive = true;
|
|
68
|
+
}
|
|
58
69
|
}
|
|
59
70
|
parent = parent.$parent;
|
|
60
71
|
}
|
|
@@ -93,20 +104,35 @@ var View = {
|
|
|
93
104
|
matched.instances[name] = knode.componentInstance;
|
|
94
105
|
};
|
|
95
106
|
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
data.
|
|
107
|
+
// register instance in init hook
|
|
108
|
+
// in case kept-alive component be actived when routes changed
|
|
109
|
+
data.hook.init = function (knode) {
|
|
110
|
+
if (knode.data.keepAlive &&
|
|
111
|
+
knode.componentInstance &&
|
|
112
|
+
knode.componentInstance !== matched.instances[name]
|
|
113
|
+
) {
|
|
114
|
+
matched.instances[name] = knode.componentInstance;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
99
117
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
118
|
+
// resolve props
|
|
119
|
+
var propsToPass = data.props = resolveProps(route, matched.props && matched.props[name]);
|
|
120
|
+
if (propsToPass) {
|
|
121
|
+
// clone to prevent mutation
|
|
122
|
+
propsToPass = data.props = extend({}, propsToPass);
|
|
123
|
+
// pass non-declared props as attrs
|
|
124
|
+
var attrs = data.attrs = data.attrs || {};
|
|
125
|
+
for (var key in propsToPass) {
|
|
126
|
+
if (!component.props || !(key in component.props)) {
|
|
127
|
+
attrs[key] = propsToPass[key];
|
|
128
|
+
delete propsToPass[key];
|
|
129
|
+
}
|
|
104
130
|
}
|
|
105
131
|
}
|
|
106
132
|
|
|
107
133
|
return h(component, data, children)
|
|
108
134
|
}
|
|
109
|
-
}
|
|
135
|
+
}
|
|
110
136
|
|
|
111
137
|
function resolveProps (route, config) {
|
|
112
138
|
switch (typeof config) {
|
|
@@ -227,7 +253,6 @@ function stringifyQuery (obj) {
|
|
|
227
253
|
|
|
228
254
|
/* */
|
|
229
255
|
|
|
230
|
-
|
|
231
256
|
var trailingSlashRE = /\/?$/;
|
|
232
257
|
|
|
233
258
|
function createRoute (
|
|
@@ -370,7 +395,7 @@ var toTypes = [String, Object];
|
|
|
370
395
|
var eventTypes = [String, Array];
|
|
371
396
|
|
|
372
397
|
var Link = {
|
|
373
|
-
name: '
|
|
398
|
+
name: 'RouterLink',
|
|
374
399
|
props: {
|
|
375
400
|
to: {
|
|
376
401
|
type: toTypes,
|
|
@@ -405,17 +430,17 @@ var Link = {
|
|
|
405
430
|
var globalExactActiveClass = router.options.linkExactActiveClass;
|
|
406
431
|
// Support global empty active class
|
|
407
432
|
var activeClassFallback = globalActiveClass == null
|
|
408
|
-
|
|
409
|
-
|
|
433
|
+
? 'router-link-active'
|
|
434
|
+
: globalActiveClass;
|
|
410
435
|
var exactActiveClassFallback = globalExactActiveClass == null
|
|
411
|
-
|
|
412
|
-
|
|
436
|
+
? 'router-link-exact-active'
|
|
437
|
+
: globalExactActiveClass;
|
|
413
438
|
var activeClass = this.activeClass == null
|
|
414
|
-
|
|
415
|
-
|
|
439
|
+
? activeClassFallback
|
|
440
|
+
: this.activeClass;
|
|
416
441
|
var exactActiveClass = this.exactActiveClass == null
|
|
417
|
-
|
|
418
|
-
|
|
442
|
+
? exactActiveClassFallback
|
|
443
|
+
: this.exactActiveClass;
|
|
419
444
|
var compareTarget = location.path
|
|
420
445
|
? createRoute(null, location, null, router)
|
|
421
446
|
: route;
|
|
@@ -455,7 +480,6 @@ var Link = {
|
|
|
455
480
|
if (a) {
|
|
456
481
|
// in case the <a> is a static node
|
|
457
482
|
a.isStatic = false;
|
|
458
|
-
var extend = _Kdu.util.extend;
|
|
459
483
|
var aData = a.data = extend({}, a.data);
|
|
460
484
|
aData.on = on;
|
|
461
485
|
var aAttrs = a.data.attrs = extend({}, a.data.attrs);
|
|
@@ -468,7 +492,7 @@ var Link = {
|
|
|
468
492
|
|
|
469
493
|
return h(this.tag, data, this.$slots.default)
|
|
470
494
|
}
|
|
471
|
-
}
|
|
495
|
+
}
|
|
472
496
|
|
|
473
497
|
function guardEvent (e) {
|
|
474
498
|
// don't redirect with control keys
|
|
@@ -546,8 +570,8 @@ function install (Kdu) {
|
|
|
546
570
|
get: function get () { return this._routerRoot._route }
|
|
547
571
|
});
|
|
548
572
|
|
|
549
|
-
Kdu.component('
|
|
550
|
-
Kdu.component('
|
|
573
|
+
Kdu.component('RouterView', View);
|
|
574
|
+
Kdu.component('RouterLink', Link);
|
|
551
575
|
|
|
552
576
|
var strats = Kdu.config.optionMergeStrategies;
|
|
553
577
|
// use the same hook merging strategy for route hooks
|
|
@@ -1057,7 +1081,6 @@ function pathToRegexp (path, keys, options) {
|
|
|
1057
1081
|
|
|
1058
1082
|
return stringToRegexp(/** @type {string} */ (path), /** @type {!Array} */ (keys), options)
|
|
1059
1083
|
}
|
|
1060
|
-
|
|
1061
1084
|
pathToRegexp_1.parse = parse_1;
|
|
1062
1085
|
pathToRegexp_1.compile = compile_1;
|
|
1063
1086
|
pathToRegexp_1.tokensToFunction = tokensToFunction_1;
|
|
@@ -1073,16 +1096,24 @@ function fillParams (
|
|
|
1073
1096
|
params,
|
|
1074
1097
|
routeMsg
|
|
1075
1098
|
) {
|
|
1099
|
+
params = params || {};
|
|
1076
1100
|
try {
|
|
1077
1101
|
var filler =
|
|
1078
1102
|
regexpCompileCache[path] ||
|
|
1079
1103
|
(regexpCompileCache[path] = pathToRegexp_1.compile(path));
|
|
1080
|
-
|
|
1104
|
+
|
|
1105
|
+
// Fix #2505 resolving asterisk routes { name: 'not-found', params: { pathMatch: '/not-found' }}
|
|
1106
|
+
if (params.pathMatch) { params[0] = params.pathMatch; }
|
|
1107
|
+
|
|
1108
|
+
return filler(params, { pretty: true })
|
|
1081
1109
|
} catch (e) {
|
|
1082
1110
|
if (process.env.NODE_ENV !== 'production') {
|
|
1083
1111
|
warn(false, ("missing param for " + routeMsg + ": " + (e.message)));
|
|
1084
1112
|
}
|
|
1085
1113
|
return ''
|
|
1114
|
+
} finally {
|
|
1115
|
+
// delete the 0 if it was added
|
|
1116
|
+
delete params[0];
|
|
1086
1117
|
}
|
|
1087
1118
|
}
|
|
1088
1119
|
|
|
@@ -1253,7 +1284,6 @@ function normalizePath (path, parent, strict) {
|
|
|
1253
1284
|
|
|
1254
1285
|
/* */
|
|
1255
1286
|
|
|
1256
|
-
|
|
1257
1287
|
function normalizeLocation (
|
|
1258
1288
|
raw,
|
|
1259
1289
|
current,
|
|
@@ -1262,15 +1292,17 @@ function normalizeLocation (
|
|
|
1262
1292
|
) {
|
|
1263
1293
|
var next = typeof raw === 'string' ? { path: raw } : raw;
|
|
1264
1294
|
// named target
|
|
1265
|
-
if (next.
|
|
1295
|
+
if (next._normalized) {
|
|
1266
1296
|
return next
|
|
1297
|
+
} else if (next.name) {
|
|
1298
|
+
return extend({}, raw)
|
|
1267
1299
|
}
|
|
1268
1300
|
|
|
1269
1301
|
// relative params
|
|
1270
1302
|
if (!next.path && next.params && current) {
|
|
1271
|
-
next =
|
|
1303
|
+
next = extend({}, next);
|
|
1272
1304
|
next._normalized = true;
|
|
1273
|
-
var params =
|
|
1305
|
+
var params = extend(extend({}, current.params), next.params);
|
|
1274
1306
|
if (current.name) {
|
|
1275
1307
|
next.name = current.name;
|
|
1276
1308
|
next.params = params;
|
|
@@ -1308,16 +1340,10 @@ function normalizeLocation (
|
|
|
1308
1340
|
}
|
|
1309
1341
|
}
|
|
1310
1342
|
|
|
1311
|
-
function assign (a, b) {
|
|
1312
|
-
for (var key in b) {
|
|
1313
|
-
a[key] = b[key];
|
|
1314
|
-
}
|
|
1315
|
-
return a
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
1343
|
/* */
|
|
1319
1344
|
|
|
1320
1345
|
|
|
1346
|
+
|
|
1321
1347
|
function createMatcher (
|
|
1322
1348
|
routes,
|
|
1323
1349
|
router
|
|
@@ -1361,10 +1387,8 @@ function createMatcher (
|
|
|
1361
1387
|
}
|
|
1362
1388
|
}
|
|
1363
1389
|
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
return _createRoute(record, location, redirectedFrom)
|
|
1367
|
-
}
|
|
1390
|
+
location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""));
|
|
1391
|
+
return _createRoute(record, location, redirectedFrom)
|
|
1368
1392
|
} else if (location.path) {
|
|
1369
1393
|
location.params = {};
|
|
1370
1394
|
for (var i = 0; i < pathList.length; i++) {
|
|
@@ -1385,8 +1409,8 @@ function createMatcher (
|
|
|
1385
1409
|
) {
|
|
1386
1410
|
var originalRedirect = record.redirect;
|
|
1387
1411
|
var redirect = typeof originalRedirect === 'function'
|
|
1388
|
-
|
|
1389
|
-
|
|
1412
|
+
? originalRedirect(createRoute(record, location, null, router))
|
|
1413
|
+
: originalRedirect;
|
|
1390
1414
|
|
|
1391
1415
|
if (typeof redirect === 'string') {
|
|
1392
1416
|
redirect = { path: redirect };
|
|
@@ -1500,7 +1524,8 @@ function matchRoute (
|
|
|
1500
1524
|
var key = regex.keys[i - 1];
|
|
1501
1525
|
var val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i];
|
|
1502
1526
|
if (key) {
|
|
1503
|
-
|
|
1527
|
+
// Fix #1994: using * with props: true generates a param named 0
|
|
1528
|
+
params[key.name || 'pathMatch'] = val;
|
|
1504
1529
|
}
|
|
1505
1530
|
}
|
|
1506
1531
|
|
|
@@ -1513,12 +1538,17 @@ function resolveRecordPath (path, record) {
|
|
|
1513
1538
|
|
|
1514
1539
|
/* */
|
|
1515
1540
|
|
|
1516
|
-
|
|
1517
1541
|
var positionStore = Object.create(null);
|
|
1518
1542
|
|
|
1519
1543
|
function setupScroll () {
|
|
1520
1544
|
// Fix for #1585 for Firefox
|
|
1521
|
-
|
|
1545
|
+
// Fix for #2195 Add optional third attribute to workaround a bug in safari https://bugs.webkit.org/show_bug.cgi?id=182678
|
|
1546
|
+
// Fix for #2774 Support for apps loaded from Windows file shares not mapped to network drives: replaced location.origin with
|
|
1547
|
+
// window.location.protocol + '//' + window.location.host
|
|
1548
|
+
// location.host contains the port and location.hostname doesn't
|
|
1549
|
+
var protocolAndPath = window.location.protocol + '//' + window.location.host;
|
|
1550
|
+
var absolutePath = window.location.href.replace(protocolAndPath, '');
|
|
1551
|
+
window.history.replaceState({ key: getStateKey() }, '', absolutePath);
|
|
1522
1552
|
window.addEventListener('popstate', function (e) {
|
|
1523
1553
|
saveScrollPosition();
|
|
1524
1554
|
if (e.state && e.state.key) {
|
|
@@ -1549,7 +1579,7 @@ function handleScroll (
|
|
|
1549
1579
|
// wait until re-render finishes before scrolling
|
|
1550
1580
|
router.app.$nextTick(function () {
|
|
1551
1581
|
var position = getScrollPosition();
|
|
1552
|
-
var shouldScroll = behavior(to, from, isPop ? position : null);
|
|
1582
|
+
var shouldScroll = behavior.call(router, to, from, isPop ? position : null);
|
|
1553
1583
|
|
|
1554
1584
|
if (!shouldScroll) {
|
|
1555
1585
|
return
|
|
@@ -2090,7 +2120,6 @@ function bindEnterGuard (
|
|
|
2090
2120
|
) {
|
|
2091
2121
|
return function routeEnterGuard (to, from, next) {
|
|
2092
2122
|
return guard(to, from, function (cb) {
|
|
2093
|
-
next(cb);
|
|
2094
2123
|
if (typeof cb === 'function') {
|
|
2095
2124
|
cbs.push(function () {
|
|
2096
2125
|
// #750
|
|
@@ -2101,6 +2130,7 @@ function bindEnterGuard (
|
|
|
2101
2130
|
poll(cb, match.instances, key, isValid);
|
|
2102
2131
|
});
|
|
2103
2132
|
}
|
|
2133
|
+
next(cb);
|
|
2104
2134
|
})
|
|
2105
2135
|
}
|
|
2106
2136
|
}
|
|
@@ -2111,7 +2141,10 @@ function poll (
|
|
|
2111
2141
|
key,
|
|
2112
2142
|
isValid
|
|
2113
2143
|
) {
|
|
2114
|
-
if (
|
|
2144
|
+
if (
|
|
2145
|
+
instances[key] &&
|
|
2146
|
+
!instances[key]._isBeingDestroyed // do not reuse being destroyed instance
|
|
2147
|
+
) {
|
|
2115
2148
|
cb(instances[key]);
|
|
2116
2149
|
} else if (isValid()) {
|
|
2117
2150
|
setTimeout(function () {
|
|
@@ -2122,16 +2155,16 @@ function poll (
|
|
|
2122
2155
|
|
|
2123
2156
|
/* */
|
|
2124
2157
|
|
|
2125
|
-
|
|
2126
|
-
var HTML5History = (function (History$$1) {
|
|
2158
|
+
var HTML5History = /*@__PURE__*/(function (History$$1) {
|
|
2127
2159
|
function HTML5History (router, base) {
|
|
2128
2160
|
var this$1 = this;
|
|
2129
2161
|
|
|
2130
2162
|
History$$1.call(this, router, base);
|
|
2131
2163
|
|
|
2132
2164
|
var expectScroll = router.options.scrollBehavior;
|
|
2165
|
+
var supportsScroll = supportsPushState && expectScroll;
|
|
2133
2166
|
|
|
2134
|
-
if (
|
|
2167
|
+
if (supportsScroll) {
|
|
2135
2168
|
setupScroll();
|
|
2136
2169
|
}
|
|
2137
2170
|
|
|
@@ -2147,7 +2180,7 @@ var HTML5History = (function (History$$1) {
|
|
|
2147
2180
|
}
|
|
2148
2181
|
|
|
2149
2182
|
this$1.transitionTo(location, function (route) {
|
|
2150
|
-
if (
|
|
2183
|
+
if (supportsScroll) {
|
|
2151
2184
|
handleScroll(router, route, current, true);
|
|
2152
2185
|
}
|
|
2153
2186
|
});
|
|
@@ -2201,7 +2234,7 @@ var HTML5History = (function (History$$1) {
|
|
|
2201
2234
|
}(History));
|
|
2202
2235
|
|
|
2203
2236
|
function getLocation (base) {
|
|
2204
|
-
var path = window.location.pathname;
|
|
2237
|
+
var path = decodeURI(window.location.pathname);
|
|
2205
2238
|
if (base && path.indexOf(base) === 0) {
|
|
2206
2239
|
path = path.slice(base.length);
|
|
2207
2240
|
}
|
|
@@ -2210,8 +2243,7 @@ function getLocation (base) {
|
|
|
2210
2243
|
|
|
2211
2244
|
/* */
|
|
2212
2245
|
|
|
2213
|
-
|
|
2214
|
-
var HashHistory = (function (History$$1) {
|
|
2246
|
+
var HashHistory = /*@__PURE__*/(function (History$$1) {
|
|
2215
2247
|
function HashHistory (router, base, fallback) {
|
|
2216
2248
|
History$$1.call(this, router, base);
|
|
2217
2249
|
// check history fallback deeplinking
|
|
@@ -2320,7 +2352,22 @@ function getHash () {
|
|
|
2320
2352
|
// consistent across browsers - Firefox will pre-decode it!
|
|
2321
2353
|
var href = window.location.href;
|
|
2322
2354
|
var index = href.indexOf('#');
|
|
2323
|
-
|
|
2355
|
+
// empty path
|
|
2356
|
+
if (index < 0) { return '' }
|
|
2357
|
+
|
|
2358
|
+
href = href.slice(index + 1);
|
|
2359
|
+
// decode the hash but not the search or hash
|
|
2360
|
+
// as search(query) is already decoded
|
|
2361
|
+
var searchIndex = href.indexOf('?');
|
|
2362
|
+
if (searchIndex < 0) {
|
|
2363
|
+
var hashIndex = href.indexOf('#');
|
|
2364
|
+
if (hashIndex > -1) { href = decodeURI(href.slice(0, hashIndex)) + href.slice(hashIndex); }
|
|
2365
|
+
else { href = decodeURI(href); }
|
|
2366
|
+
} else {
|
|
2367
|
+
if (searchIndex > -1) { href = decodeURI(href.slice(0, searchIndex)) + href.slice(searchIndex); }
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
return href
|
|
2324
2371
|
}
|
|
2325
2372
|
|
|
2326
2373
|
function getUrl (path) {
|
|
@@ -2348,8 +2395,7 @@ function replaceHash (path) {
|
|
|
2348
2395
|
|
|
2349
2396
|
/* */
|
|
2350
2397
|
|
|
2351
|
-
|
|
2352
|
-
var AbstractHistory = (function (History$$1) {
|
|
2398
|
+
var AbstractHistory = /*@__PURE__*/(function (History$$1) {
|
|
2353
2399
|
function AbstractHistory (router, base) {
|
|
2354
2400
|
History$$1.call(this, router, base);
|
|
2355
2401
|
this.stack = [];
|
|
@@ -2407,6 +2453,8 @@ var AbstractHistory = (function (History$$1) {
|
|
|
2407
2453
|
|
|
2408
2454
|
/* */
|
|
2409
2455
|
|
|
2456
|
+
|
|
2457
|
+
|
|
2410
2458
|
var KduRouter = function KduRouter (options) {
|
|
2411
2459
|
if ( options === void 0 ) options = {};
|
|
2412
2460
|
|
|
@@ -2470,7 +2518,18 @@ KduRouter.prototype.init = function init (app /* Kdu component instance */) {
|
|
|
2470
2518
|
|
|
2471
2519
|
this.apps.push(app);
|
|
2472
2520
|
|
|
2473
|
-
//
|
|
2521
|
+
// set up app destroyed handler
|
|
2522
|
+
app.$once('hook:destroyed', function () {
|
|
2523
|
+
// clean out app from this.apps array once destroyed
|
|
2524
|
+
var index = this$1.apps.indexOf(app);
|
|
2525
|
+
if (index > -1) { this$1.apps.splice(index, 1); }
|
|
2526
|
+
// ensure we still have a main app or null if no apps
|
|
2527
|
+
// we do not release the router so it can be reused
|
|
2528
|
+
if (this$1.app === app) { this$1.app = this$1.apps[0] || null; }
|
|
2529
|
+
});
|
|
2530
|
+
|
|
2531
|
+
// main app previously initialized
|
|
2532
|
+
// return as we don't need to set up new history listener
|
|
2474
2533
|
if (this.app) {
|
|
2475
2534
|
return
|
|
2476
2535
|
}
|
|
@@ -2560,9 +2619,10 @@ KduRouter.prototype.resolve = function resolve (
|
|
|
2560
2619
|
current,
|
|
2561
2620
|
append
|
|
2562
2621
|
) {
|
|
2622
|
+
current = current || this.history.current;
|
|
2563
2623
|
var location = normalizeLocation(
|
|
2564
2624
|
to,
|
|
2565
|
-
current
|
|
2625
|
+
current,
|
|
2566
2626
|
append,
|
|
2567
2627
|
this
|
|
2568
2628
|
);
|
|
@@ -2603,7 +2663,7 @@ function createHref (base, fullPath, mode) {
|
|
|
2603
2663
|
}
|
|
2604
2664
|
|
|
2605
2665
|
KduRouter.install = install;
|
|
2606
|
-
KduRouter.version = '3.0.
|
|
2666
|
+
KduRouter.version = '3.0.7';
|
|
2607
2667
|
|
|
2608
2668
|
if (inBrowser && window.Kdu) {
|
|
2609
2669
|
window.Kdu.use(KduRouter);
|