Skip to content

Commit

Permalink
Redirects coordinates pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Fi1osof committed Mar 14, 2021
1 parent 3ec93c3 commit cd170b2
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/pages/Resource/index.tsx
Expand Up @@ -135,7 +135,28 @@ const ResourcePage: Page<ResourcePageProps> = () => {
}

ResourcePage.getInitialProps = async (context) => {
const { apolloClient } = context
const { apolloClient, query, res } = context

/**
* Редиректим со страниц с даннми координат
*/
if (res && Array.isArray(query.path) && query.path.length) {
const path = [...query.path]

const coordsPath = path.find((n) => /^@\d+/.test(n))

if (coordsPath) {
path.pop()

// TODO Поправить тип для res
// https://freecode.academy/tasks/ckm95xkamgc0h07306qnymjuk
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
res.redirect(301, '/' + path.join('/'))

return {}
}
}

const variables = getResourceVariables(context)

Expand Down

0 comments on commit cd170b2

Please sign in to comment.