Skip to content

Commit 41733e6

Browse files
committed
add popup option for redirect
1 parent dd993fd commit 41733e6

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

reflex/.templates/web/utils/state.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ export const applyEvent = async (event, socket, navigate, params) => {
210210
return false;
211211
}
212212
if (event.payload.external) {
213-
window.open(event.payload.path, "_blank", "noopener");
213+
window.open(
214+
event.payload.path,
215+
"_blank",
216+
"noopener" + (event.payload.popup ? ",popup" : ""),
217+
);
214218
return false;
215219
}
216220
const url = urlFrom(event.payload.path);

reflex/event.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Annotated,
1414
Any,
1515
Generic,
16+
Literal,
1617
NoReturn,
1718
Protocol,
1819
TypeVar,
@@ -962,16 +963,37 @@ def fn():
962963
)
963964

964965

966+
@overload
967+
def redirect(
968+
path: str | Var[str],
969+
*,
970+
is_external: Literal[False] = False,
971+
replace: bool = False,
972+
) -> EventSpec: ...
973+
974+
975+
@overload
976+
def redirect(
977+
path: str | Var[str],
978+
*,
979+
is_external: Literal[True],
980+
popup: bool = False,
981+
) -> EventSpec: ...
982+
983+
965984
def redirect(
966985
path: str | Var[str],
986+
*,
967987
is_external: bool = False,
988+
popup: bool = False,
968989
replace: bool = False,
969990
) -> EventSpec:
970991
"""Redirect to a new path.
971992
972993
Args:
973994
path: The path to redirect to.
974995
is_external: Whether to open in new tab or not.
996+
popup: Whether to open in a new window or not.
975997
replace: If True, the current page will not create a new history entry.
976998
977999
Returns:
@@ -982,6 +1004,7 @@ def redirect(
9821004
get_fn_signature(redirect),
9831005
path=path,
9841006
external=is_external,
1007+
popup=popup,
9851008
replace=replace,
9861009
)
9871010

0 commit comments

Comments
 (0)