Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the Link is clicked, there is no reaction to Ctrl and Shift. And history entries are duplicated. #253

Closed
ghost opened this issue Nov 28, 2017 · 3 comments

Comments

@ghost
Copy link

ghost commented Nov 28, 2017

Hello. I've found that multiple clicks on same Link cause duplication of records. And also that clicks on Link with the holded Ctrl and Shift are not processed, as it should be.
I thought this was a mistake and I hope for understanding. I fixed it and hopefully you use it.

~42 line in preact-router/src/index.js:

// ...
function route(url, replace=false) {
	if (typeof url!=='string' && url.url) {
		replace = url.replace;
		url = url.url;
	}

	// only push URL into history if we can handle it
	if (url !== getCurrentUrl() && canRoute(url)) {
		setUrl(url, replace ? 'replace' : 'push');
	}

	return routeTo(url);
}
//...

~96 line:

function handleLinkClick(e) {
	if (e.button==0) {
		if(e.ctrlKey || e.shiftKey) return true;

		prevent(e);

		routeFromLink(e.currentTarget || e.target || this);
	}
}
// ...

Thank you in advance.

P.S. Does the preact-router cache pages? Let's say when going back and forward on history.

@ghost ghost changed the title When the Link is clicked, there is no reaction to Ctrl and Shift. And history entries is duplicated. When the Link is clicked, there is no reaction to Ctrl and Shift. And history entries is duplicated. I fixed it. Nov 28, 2017
@ghost ghost changed the title When the Link is clicked, there is no reaction to Ctrl and Shift. And history entries is duplicated. I fixed it. When the Link is clicked, there is no reaction to Ctrl and Shift. And history entries is duplicated in Chrome. Nov 28, 2017
@ghost ghost changed the title When the Link is clicked, there is no reaction to Ctrl and Shift. And history entries is duplicated in Chrome. When the Link is clicked, there is no reaction to Ctrl and Shift. And history entries is duplicated. Nov 28, 2017
@ghost ghost changed the title When the Link is clicked, there is no reaction to Ctrl and Shift. And history entries is duplicated. When the Link is clicked, there is no reaction to Ctrl and Shift. And history entries are duplicated. Nov 28, 2017
@ghost ghost closed this as completed Dec 6, 2017
@ghost ghost reopened this Dec 6, 2017
@developit
Copy link
Member

Hi there - try using a plain old <a> element.

@tysonmatanich
Copy link

@developit Using a plain old <a> works correctly but then looses the behavior that <Link activeClassName="active"> was designed for.

@tysonmatanich
Copy link

Another option would be to change <Link to <a in match.js:

export const Link = ({ activeClassName, path, ...props }) => (
	<Match path={path || props.href}>
		{ ({ matches }) => (
			<a {...props} class={[props.class || props.className, matches && activeClassName].filter(Boolean).join(' ')} />
		) }
	</Match>
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants