diff --git a/README.md b/README.md index 1d33376..f348193 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,9 @@ The current params taken from the route. E.g. `/foo/:bar` becomes available as An object containing the current queryString. `/foo?bin=baz` becomes `{ bin: 'baz' }`. +### `state.href` +An object containing the current href. `/foo?bin=baz` becomes `foo`. + ### `state.route` The current name of the route used in the router (e.g. `/foo/:bar`). diff --git a/index.js b/index.js index 210455c..2874850 100644 --- a/index.js +++ b/index.js @@ -122,16 +122,17 @@ Choo.prototype.start = function () { } } - var location = this._createLocation() - this._tree = this.router(location) + this.state.href = this._createLocation() + this._tree = this.router(this.state.href) this.state.query = nanoquery(window.location.search) - assert.ok(this._tree, 'choo.start: no valid DOM node returned for location ' + location) + assert.ok(this._tree, 'choo.start: no valid DOM node returned for location ' + this.state.href) this.emitter.prependListener(self._events.RENDER, nanoraf(function () { var renderTiming = nanotiming('choo.render') - var newTree = self.router(self._createLocation()) - assert.ok(newTree, 'choo.render: no valid DOM node returned for location ' + location) + self.state.href = self._createLocation() + var newTree = self.router(self.state.href) + assert.ok(newTree, 'choo.render: no valid DOM node returned for location ' + self.state.href) assert.equal(self._tree.nodeName, newTree.nodeName, 'choo.render: The target node <' + self._tree.nodeName.toLowerCase() + '> is not the same type as the new node <' + @@ -182,6 +183,7 @@ Choo.prototype.toString = function (location, state) { assert.equal(typeof location, 'string', 'choo.toString: location should be type string') assert.equal(typeof this.state, 'object', 'choo.toString: state should be type object') + this.state.href = location.replace(/\?*.$/, '') this.state.query = nanoquery(location) var html = this.router(location) assert.ok(html, 'choo.toString: no valid value returned for the route ' + location) diff --git a/package.json b/package.json index 362d69e..b5fb451 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "example" ], "scripts": { - "build": "mkdir -p dist/ && browserify index -p bundle-collapser/plugin > dist/bundle.js && browserify index -g unassertify -g uglifyify -p bundle-collapser/plugin | uglifyjs --mangle-props -c unsafe,properties,dead_code,comparisons,evaluate,hoist_funs,if_return,join_vars,pure_getters,reduce_vars,collapse_vars --toplevel > dist/bundle.min.js && zopfli -i 100 dist/bundle.min.js && wc -c < dist/bundle.min.js.gz | pretty-bytes", + "build": "mkdir -p dist/ && browserify index -p bundle-collapser/plugin > dist/bundle.js && browserify index -g unassertify -g uglifyify -p bundle-collapser/plugin | uglifyjs --mangle-props -c unsafe,properties,dead_code,comparisons,evaluate,hoist_funs,if_return,join_vars,pure_getters,reduce_vars,collapse_vars --toplevel > dist/bundle.min.js && cat dist/bundle.min.js | gzip --best --stdout | wc -c | pretty-bytes", "deps": "dependency-check --entry ./html.js . && dependency-check . --extra --no-dev --entry ./html.js", "inspect": "browserify --full-paths index -g unassertify -g uglifyify | discify --open", "prepublish": "npm run build", @@ -46,7 +46,6 @@ "bundle-collapser": "^1.2.1", "dependency-check": "^2.8.0", "discify": "^1.6.0", - "node-zopfli": "^2.0.2", "pretty-bytes-cli": "^2.0.0", "spok": "^0.8.1", "standard": "^10.0.0",