How to use the preact-router.getCurrentUrl function in preact-router

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 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 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 preactjs / preact-router / src / match.js View on Github external
render(props) {
		let url = this.nextUrl || getCurrentUrl(),
			path = url.replace(/\?.+$/,'');
		this.nextUrl = null;
		return props.children({
			url,
			path,
			matches: exec(path, props.path, {}) !== false
		});
	}
}
github GladysAssistant / Gladys / front / src / utils / getDefaultState.js View on Github external
function getDefaultState() {
  const session = config.gatewayMode ? new GatewaySession() : config.demoMode ? new DemoSession() : new Session();
  const httpClient = config.demoMode
    ? new DemoHttpClient()
    : config.gatewayMode
    ? new GatewayHttpClient(session)
    : new HttpClient(session);
  const state = {
    httpClient,
    session,
    currentUrl: getCurrentUrl(),
    user: {
      language: navigator.language === 'fr' ? 'fr' : 'en'
    },
    showDropDown: false
  };
  return state;
}

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