From 5ac5eb550380e9c9a5c4fdbbbf08fadbe01ff4a9 Mon Sep 17 00:00:00 2001 From: rr- Date: Thu, 7 Jul 2016 21:18:35 +0200 Subject: client/general: refactor URL parameter handling --- client/js/router.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'client/js/router.js') diff --git a/client/js/router.js b/client/js/router.js index 426d6d4..490b804 100644 --- a/client/js/router.js +++ b/client/js/router.js @@ -39,7 +39,7 @@ class Context { this.title = document.title; this.state = state || {}; this.state.path = path; - this.params = {}; + this.parameters = {}; } pushState() { @@ -61,14 +61,14 @@ class Route { middleware(fn) { return (ctx, next) => { - if (this.match(ctx.path, ctx.params)) { + if (this.match(ctx.path, ctx.parameters)) { return fn(ctx, next); } next(); }; } - match(path, params) { + match(path, parameters) { const keys = this.keys; const qsIndex = path.indexOf('?'); const pathname = ~qsIndex ? path.slice(0, qsIndex) : path; @@ -81,8 +81,9 @@ class Route { for (let i = 1, len = m.length; i < len; ++i) { const key = keys[i - 1]; const val = _decodeURLEncodedURIComponent(m[i]); - if (val !== undefined || !(hasOwnProperty.call(params, key.name))) { - params[key.name] = val; + if (val !== undefined || + !(hasOwnProperty.call(parameters, key.name))) { + parameters[key.name] = val; } } -- cgit v1.3