Browse Source

impl pushState

Yuki Takei 4 years ago
parent
commit
b666f29e9e
1 changed files with 6 additions and 0 deletions
  1. 6 0
      packages/app/src/components/SearchPage.tsx

+ 6 - 0
packages/app/src/components/SearchPage.tsx

@@ -134,6 +134,12 @@ export const SearchPage = (props: Props): JSX.Element => {
     };
   }, [initQ]);
 
+  // push state
+  useEffect(() => {
+    const newUrl = new URL('/_search', 'http://example.com');
+    newUrl.searchParams.append('q', keyword);
+    window.history.pushState('', `Search - ${keyword}`, `${newUrl.pathname}${newUrl.search}`);
+  }, [keyword]);
 
   const hitsCount = data?.meta.hitsCount;
   const { offset, limit } = conditions;