href method

  1. @override
Route href(
  1. String url, {
  2. bool? removeIf,
})
override

The URL that the hyperlink points to. Read more...

Implementation

@override
Route href(String url, {bool? removeIf}) {
  on.call('click', (Element element, Event event) {
    if (window.location.href == window.location.origin + url) return this;

    if (_history == false) {
      window.history.replaceState({}, url, window.location.origin + url);
    } else {
      window.history.pushState({}, url, window.location.origin + url);
    }

    window.dispatchEvent(Event(routerEvent));
  });

  if (removeIf != true && node.attrs != null) {
    VirtualAttr attr = VirtualAttr('onclick', 'return false');
    node.attrs!.add(attr);
  }

  return this;
}