Skip to content

Commit

Permalink
fix unnecessary redirect when browsing /#**
Browse files Browse the repository at this point in the history
  • Loading branch information
k1r0s committed Nov 6, 2017
1 parent 9a784d8 commit 063e7c8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Path from 'path-parser';
const ROUTE_LISTENER_POOL = [];
let FIRST_COMPONENT_HAS_MOUNTED = false;
const gotoDefault = _ => {
if(!FIRST_COMPONENT_HAS_MOUNTED) {
if(!FIRST_COMPONENT_HAS_MOUNTED && !location.hash) {
setTimeout(navigate, 1, "/");
FIRST_COMPONENT_HAS_MOUNTED = true;
}
Expand Down Expand Up @@ -74,7 +74,5 @@ export class RouterOutlet extends PathLookup {
}
}

export const Link = props => {
props["href"] = "#" + props.href;
return h("a", props, props.children);
};
export const Link = ({ href, children, ...props }) =>
h("a", { href: `#${href}`, ...props }, children);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"devDependencies": {
"babel-core": "^6.26.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"rollup": "^0.50.0",
"rollup-plugin-babel": "^3.0.2"
Expand Down
3 changes: 2 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default {
]
],
"plugins": [
"external-helpers"
"external-helpers",
"transform-object-rest-spread"
]
})
]
Expand Down
34 changes: 30 additions & 4 deletions routlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ var createClass = function () {



var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];

for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}

return target;
};



var inherits = function (subClass, superClass) {
Expand All @@ -179,7 +193,17 @@ var inherits = function (subClass, superClass) {



var objectWithoutProperties = function (obj, keys) {
var target = {};

for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
}

return target;
};

var possibleConstructorReturn = function (self, call) {
if (!self) {
Expand All @@ -192,7 +216,7 @@ var possibleConstructorReturn = function (self, call) {
var ROUTE_LISTENER_POOL = [];
var FIRST_COMPONENT_HAS_MOUNTED = false;
var gotoDefault = function gotoDefault(_) {
if (!FIRST_COMPONENT_HAS_MOUNTED) {
if (!FIRST_COMPONENT_HAS_MOUNTED && !location.hash) {
setTimeout(navigate, 1, "/");
FIRST_COMPONENT_HAS_MOUNTED = true;
}
Expand Down Expand Up @@ -309,9 +333,11 @@ var RouterOutlet = function (_PathLookup) {
return RouterOutlet;
}(PathLookup);

var Link = function Link(props) {
props["href"] = "#" + props.href;
return preact.h("a", props, props.children);
var Link = function Link(_ref6) {
var href = _ref6.href,
children = _ref6.children,
props = objectWithoutProperties(_ref6, ["href", "children"]);
return preact.h("a", _extends({ href: "#" + href }, props), children);
};

exports.renderOnRoute = renderOnRoute;
Expand Down

0 comments on commit 063e7c8

Please sign in to comment.