浏览代码

Add get_query_params method (#244)

Thomas Brandého 2 年之前
父节点
当前提交
51a635fe75
共有 1 个文件被更改,包括 11 次插入1 次删除
  1. 11 1
      pynecone/state.py

+ 11 - 1
pynecone/state.py

@@ -267,7 +267,17 @@ class State(Base, ABC):
         Returns:
             The current page.
         """
-        return cls.router_data["pathname"]
+        return cls.router_data.get("pathname", "")
+
+    def get_query_params(cls) -> Dict[str, str]:
+        """Obtain the query parameters for the queried page.
+
+        The query object contains both the URI parameters and the GET parameters.
+
+        Returns:
+            The dict of query parameters.
+        """
+        return cls.router_data.get("query", {})
 
     def __getattribute__(self, name: str) -> Any:
         """Get the state var.