Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'preact-router' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
del(`articles/${this.state.item.slug}`).then(_ => {
route('/'); // back to home/dashboard
});
}
_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) {
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) && style.disabled)}
>
{items.map(({ text, level, href }) => {
let activeCss = href === url ? style.linkActive : undefined;
return (
<a class="{cx(style.link," href="{href}"></a></nav>
}).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
}
});
}
function onChange(e) {
const url = getCurrentUrl().replace(/(v\d{1,2})/, `v${e.target.value}`);
route(url);
}
routeToMap() {
this.resetSelectedPin();
route('/maps', true);
}
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)
}
}
routeToRegister() {
route("/register", true);
}
goToCreate () {
if (user) {
route('/stories/create')
} else {
route('/login')
}
}