0.0.1 • Published 3 years ago
next-url-encoding v0.0.1
next-url-encoding
handle full urls in nextjs SSR methods easily.
How to use
In the browser make sure to cipher
the content so it displays like a slug.
When ready to send network request simply decipher
the string. If you try to pass in full URL slugs or even urls with encodeURI
the SSR methods will not work, thats where this package comes into play.
const target = "https://a11ywatch.com";
const c = codecs.cipher(target); // encoded
window.location.href = `${target}/reports/${c}`;
// in nextjs ssr method
export const getServerSideProps = async (context) => {
const { slug } = context.params ?? {};
const [url] = Array.isArray(slug) ? slug : [];
let targetUrl = codecs.decipher(url);
// do something with the url slug safely
await fetch(targetUrl);
};
0.0.1
3 years ago