How to use preact-router - 10 common examples

To help you get started, we’ve selected a few preact-router examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lukeed / preact-realworld-app / src / routes / article.js View on Github external
del(`articles/${this.state.item.slug}`).then(_ => {
			route('/'); // back to home/dashboard
		});
	}
github keemor / keemor.github.io / src / components / header.js View on Github external
_routeFromLink(node) {
        // only valid elements
        if (!node || !node.getAttribute) return;

        let href = node.getAttribute('href'),
            target = node.getAttribute('target');

        // ignore links with targets and non-path URLs
        if (!href || !href.match(/^\//g) || (target && !target.match(/^_?self$/i))) return;

        // attempt to route, if no match simply cede control to browser
        return route(href);
    }
    _onClick(e) {
github preactjs / preact-www / src / components / controllers / page / sidebar-nav.js View on Github external
export default function SidebarNav({ items, onClick }) {
	// Remove trailing slash to fix activeCss check below.
	// Note that netlify will always append a slash to the url so that we end
	// up with something like "foo/bar/?lang=de". That's why we first remove
	// the search params before removing the trailing slash.
	const url = getCurrentUrl()
		.replace(/\?.*/, '')
		.replace(/\/$/, '');

	return (
		<nav class="{cx(style.toc," tabindex="0"> 1) &amp;&amp; style.disabled)}
		&gt;
			{items.map(({ text, level, href }) =&gt; {
				let activeCss = href === url ? style.linkActive : undefined;
				return (
					<a class="{cx(style.link," href="{href}"></a></nav>
github TheDevPath / Navi / client / src / components / LeafletOsmMap / index.js View on Github external
}).catch((err) => {
      switch (err.response.status) {
        case 400: //duplicate pin
          const origPin = err.response.data;
          alert('This pin is already on your map.');
          /*TO DO:
          Convert popup alert to toast message
          */
          break;
        case 403: //user not signed in
          /*TO DO:
          Convert to overlay/lightbox window to sign up form
          */
          if (confirm("Would you like to sign in to save places?")) {
            route('/signin', true);
          }

          break;
        default:
          console.log(err); //error saving pin
      }
    });
  }
github preactjs / preact-www / src / components / doc-version / index.js View on Github external
function onChange(e) {
	const url = getCurrentUrl().replace(/(v\d{1,2})/, `v${e.target.value}`);
	route(url);
}
github TheDevPath / Navi / client / src / routes / home / index.js View on Github external
routeToMap() {		
		this.resetSelectedPin();
		route('/maps', true);
	}
github onfido / onfido-sdk-ui / src / components / camera / index.js View on Github external
componentWillReceiveProps (nextProps) {
    const { method } = this.props
    const { hasDocumentCaptured, hasFaceCaptured } = nextProps
    const validDocumentCapture = (hasDocumentCaptured && method === 'document')
    const validFaceCapture = (hasFaceCaptured && method === 'face')
    if (validDocumentCapture || validFaceCapture) {
      route('/', true)
    }
  }
github OpenNewsLabs / guri-vr / client / src / components / Home / index.js View on Github external
goToCreate () {
    if (user) {
      route('/stories/create')
    } else {
      route('/login')
    }
  }

preact-router

Connect your components up to that address bar.

MIT
Latest version published 1 year ago

Package Health Score

66 / 100
Full package analysis