0

We need to create hreflang tag for the pages added to the site.

In the frontend, we are trying to build the page url for the current page. Is there any way, we can build the page url apart from window.Location. There is multisite environment.

If anyone have idea how it can be achieved?

1 Answer 1

0

window.Location is a decent way to get url but you can also use NextJs's router object to get route data.

import { useRouter } from 'next/router';
const router = useRouter();

const path = router.asPath;

//Just explore this router object, you will get lot of useful properties

And just an additional information -

import { getPublicUrl, LayoutServiceData } from '@sitecore-jss/sitecore-jss-nextjs';

const publicUrl = process.env.SITE_URL ?? getPublicUrl();
// This will give you public url 

I have used a combination of above object to form desired urls.

Hope this helps !

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.