Skip to content

Commit cfef771

Browse files
authored
fix: allow project redirects to dynamic paths (#4352)
Fixes https://discord.com/channels/955905230107738152/1300622567740018730 Users cannot specify dynamic path in redirect new path.
1 parent ab2a985 commit cfef771

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

apps/builder/app/builder/features/project-settings/section-redirects.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { useState, type ChangeEvent, useRef } from "react";
2+
import { flushSync } from "react-dom";
3+
import { useStore } from "@nanostores/react";
14
import {
25
Grid,
36
Flex,
@@ -15,16 +18,14 @@ import {
1518
Tooltip,
1619
} from "@webstudio-is/design-system";
1720
import { ArrowRightIcon, TrashIcon } from "@webstudio-is/icons";
18-
import { useState, type ChangeEvent, useRef } from "react";
1921
import {
2022
PagePath,
2123
PageRedirect,
2224
ProjectNewRedirectPath,
2325
} from "@webstudio-is/sdk";
24-
import { useStore } from "@nanostores/react";
2526
import { $pages, $publishedOrigin } from "~/shared/nano-states";
2627
import { serverSyncStore } from "~/shared/sync";
27-
import { flushSync } from "react-dom";
28+
import { matchPathnamePattern } from "~/builder/shared/url-pattern";
2829
import { getExistingRoutePaths, sectionSpacing } from "./utils";
2930

3031
export const SectionRedirects = () => {
@@ -93,7 +94,13 @@ export const SectionRedirects = () => {
9394
}
9495

9596
if (newPath.startsWith("/") === true) {
96-
if (existingPaths.has(newPath) === false) {
97+
let matched = false;
98+
for (const pattern of existingPaths) {
99+
if (matchPathnamePattern(pattern, newPath)) {
100+
matched = true;
101+
}
102+
}
103+
if (matched === false) {
97104
return ["This path doesn't exist in the project"];
98105
}
99106
}

0 commit comments

Comments
 (0)