Skip to content

Commit

Permalink
redirect old urls to /material/*
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Dec 20, 2021
1 parent 6f6f4eb commit aa23f5c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/src/modules/components/AppSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Link from 'docs/src/modules/components/Link';
import { useTranslate, useUserLanguage } from 'docs/src/modules/utils/i18n';
import useLazyCSS from 'docs/src/modules/utils/useLazyCSS';
import { useRouter } from 'next/router';
import FEATURE_TOGGLE from 'docs/src/featureToggle';

const SearchButton = styled('button')(({ theme }) => {
return {
Expand Down Expand Up @@ -298,7 +299,7 @@ export default function AppSearch() {
}

// TODO: remove this logic once the migration to new structure is done.
if (router.asPath.startsWith('/material')) {
if (FEATURE_TOGGLE.enable_product_scope) {
parseUrl.href = parseUrl.href.replace(
/(?<!material\/)(getting-started|components|api|customization|guides|discover-more)(\/[^/]+\/)/,
`material/$1$2`,
Expand Down
16 changes: 12 additions & 4 deletions test/e2e-website/material-docs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,18 @@ test.describe.parallel('Material docs', () => {

const anchor = await page.locator('.DocSearch-Hits a:has-text("Card")');

await expect(anchor.first()).toHaveAttribute(
'href',
`${materialUrlPrefix}/components/cards/#main-content`,
);
if (FEATURE_TOGGLE.enable_product_scope && !materialUrlPrefix) {
// the old url doc should point to the new location
await expect(anchor.first()).toHaveAttribute(
'href',
`/material/components/cards/#main-content`,
);
} else {
await expect(anchor.first()).toHaveAttribute(
'href',
`${materialUrlPrefix}/components/cards/#main-content`,
);
}
});

test('should have correct link when searching API', async ({ page, materialUrlPrefix }) => {
Expand Down

0 comments on commit aa23f5c

Please sign in to comment.