catch-links

2019-06-13 admin

catch-links是什么

什么是catch-links,intercept local link clicks on a page

catch-links使用教程帮助文档

catch-links

intercept local link clicks on a page

This is useful for doing client-side pushState UIs.

example

Given some html:

<html>
  <body>
    <div>
      <a href="/a">aaa</a>
    </div>

    <div>
      <a href="/b">bbb</a>
    </div>

    <div>
      <a href="cc">cc</a>
    </div>

    <div>
      <a href="http://npmjs.org">npmjs</a>
    </div>

    <script src="bundle.js"></script>
  </body>
</html>

We’ll intercept the relative links <host>/a and <host>/b, printing them. The external link to npmjs.org will go through as usual.

var catchLinks = require('catch-links');

catchLinks(window, function (href) {
    console.log(href);
});

methods

var catchLinks = require('catch-links')

catchLinks(element, cb)

Fire cb(href) whenever an anchor tag descendant of element with an in-server url is clicked.

href will always be a relative path rooted at the root path.

install

With npm do:

npm install catch-links

Use browserify to bundle this library into your project.

license

MIT

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-67216.html

文章标题:catch-links

回到顶部