Skip to content

Unable to preventDefault on route-href when pushState is true #848

@powerbuoy

Description

@powerbuoy

I'm trying to prevent a link with a route-href attribute from navigating to the new URL.

When I configure the router to use hashChange instead of pushState it works fine. But if I switch to pushState preventDefault() does nothing:

import {inject} from 'aurelia-framework';

@inject(Element)
export class PreventHrefCustomAttribute {
	constructor (el) {
		this.el = el;
		this.onClick = e => {
			e.preventDefault(); // This only works when pushState: false, hashChange: true

			alert('The href should not be followed');
		};
	}

	attached () {
		this.el.addEventListener('click', this.onClick);
	}

	detached () {
		this.el.removeEventListener('click', this.onClick);
	}
}

<a route-href="route: item; params.bind: {id: item.id}" prevent-href>${item.name}</a>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions