From 2bc45b000cf4e4249bc09c06091fb19c1993aa5e Mon Sep 17 00:00:00 2001 From: Nikhil Rao Date: Fri, 9 Jun 2023 18:55:21 -0700 Subject: [PATCH] Fix pc.link with no href (#1178) --- pynecone/components/navigation/link.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/pynecone/components/navigation/link.py b/pynecone/components/navigation/link.py index 63955a986..8db1bfcbf 100644 --- a/pynecone/components/navigation/link.py +++ b/pynecone/components/navigation/link.py @@ -33,20 +33,16 @@ class Link(ChakraComponent): return {**super()._get_imports(), **NextLink.create()._get_imports()} @classmethod - def create( - cls, *children, href: Optional[Var] = None, rel: Optional[Var] = None, **props - ) -> Component: + def create(cls, *children, href: Optional[Var] = None, **props) -> Component: """Create a Link component. Args: *children: The children of the component. - href (Var): The href attribute of the link. Defaults to None. - rel (Var): The rel attribute of the link. Defaults to None. + href: The href attribute of the link. **props: The props of the component. Raises: ValueError: in case of missing children - ValueError: in case of missing href Returns: Component: The link component @@ -54,9 +50,8 @@ class Link(ChakraComponent): if href and not len(children): raise ValueError("Link without a child will not display") elif href is None and len(children): - raise ValueError("Link without 'href' props will not work.") - else: - props.update({"href": href}) - if rel: - props.update({"rel": rel}) + # Don't use a NextLink if there is no href. + props["as_"] = "Link" + if href: + props["href"] = href return super().create(*children, **props)