Skip to content

Commit

Permalink
feat(app): migrative redirection (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
axross committed May 3, 2021
1 parent 3348370 commit 77de99a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ import { getDefaultLocale, getLocales } from "../helpers/localization";
const Page: NextPage = () => null;

export const getServerSideProps: GetServerSideProps = async ({ req }) => {
if (req.url?.includes("?")) {
const searchParams = new URL(req.url, process.env.NEXT_PUBLIC_SELF_ORIGIN)
.searchParams;
const requestedLocale = getLocales().find(
(locale) => locale === searchParams.get("hl")?.toLowerCase()
);

return {
redirect: {
permanent: true,
destination: `/${requestedLocale}`,
},
};
}

const negotiator = new Negotiator(req);
const locale = negotiator.language(getLocales()) ?? getDefaultLocale();

Expand Down
15 changes: 15 additions & 0 deletions pages/posts/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ export const getServerSideProps: GetServerSideProps<
{},
{ slug: string }
> = async ({ req, params }) => {
if (req.url?.includes("?")) {
const searchParams = new URL(req.url, process.env.NEXT_PUBLIC_SELF_ORIGIN)
.searchParams;
const requestedLocale = getLocales().find(
(locale) => locale === searchParams.get("hl")?.toLowerCase()
);

return {
redirect: {
permanent: true,
destination: `/${requestedLocale}/posts/${params!.slug}`,
},
};
}

const negotiator = new Negotiator(req);
const locale = negotiator.language(getLocales()) ?? getDefaultLocale();

Expand Down

1 comment on commit 77de99a

@vercel
Copy link

@vercel vercel bot commented on 77de99a May 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.