|
1 | 1 | import { cloneElement, h, Component } from 'preact';
|
2 |
| -import { exec, pathRankSort } from './util'; |
| 2 | +import { exec, pathRankSort, assign } from './util'; |
3 | 3 |
|
4 | 4 | let customHistory = null;
|
5 | 5 |
|
@@ -94,9 +94,10 @@ function routeFromLink(node) {
|
94 | 94 |
|
95 | 95 |
|
96 | 96 | function handleLinkClick(e) {
|
97 |
| - if (e.button !== 0) return; |
98 |
| - routeFromLink(e.currentTarget || e.target || this); |
99 |
| - return prevent(e); |
| 97 | + if (e.button==0) { |
| 98 | + routeFromLink(e.currentTarget || e.target || this); |
| 99 | + return prevent(e); |
| 100 | + } |
100 | 101 | }
|
101 | 102 |
|
102 | 103 |
|
@@ -152,7 +153,7 @@ class Router extends Component {
|
152 | 153 | }
|
153 | 154 |
|
154 | 155 | this.state = {
|
155 |
| - url: this.props.url || getCurrentUrl() |
| 156 | + url: props.url || getCurrentUrl() |
156 | 157 | };
|
157 | 158 |
|
158 | 159 | initEventListeners();
|
@@ -215,12 +216,7 @@ class Router extends Component {
|
215 | 216 | if (matches) {
|
216 | 217 | if (invoke!==false) {
|
217 | 218 | let newProps = { url, matches };
|
218 |
| - // copy matches onto props |
219 |
| - for (let i in matches) { |
220 |
| - if (matches.hasOwnProperty(i)) { |
221 |
| - newProps[i] = matches[i]; |
222 |
| - } |
223 |
| - } |
| 219 | + assign(newProps, matches); |
224 | 220 | return cloneElement(vnode, newProps);
|
225 | 221 | }
|
226 | 222 | return vnode;
|
@@ -254,7 +250,7 @@ class Router extends Component {
|
254 | 250 | }
|
255 | 251 |
|
256 | 252 | const Link = (props) => (
|
257 |
| - h('a', Object.assign({}, props, { onClick: handleLinkClick })) |
| 253 | + h('a', assign({ onClick: handleLinkClick }, props)) |
258 | 254 | );
|
259 | 255 |
|
260 | 256 | const Route = props => h(props.component, props);
|
|
0 commit comments