React router with query params #1749
-
I'm trying to use the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Problem AnalysisThe pages of browser extensions (such as popup pages, options pages) run in a sandboxed environment. The URL format is different from that of standard web pages (for example: Solutions1. Use Hash Router instead of Browser RouterThe extension environment has limited support for // Use HashRouter in the extension project
import { HashRouter as Router, Routes, Route } from'react - router - dom';
function App() {
return (
<Router>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/details" element={<Details />} />
</Routes>
</Router>
);
} 2. Manually handle query parametersIf there are still problems with Hash Router, you can parse the query parameters in the URL manually: import { useLocation } from'react - router - dom';
function Details() {
const location = useLocation();
// Manually parse query parameters
const searchParams = new URLSearchParams(location.search);
const id = searchParams.get('id');
return <div>Details for ID: {id}</div>;
} 3. Use WXT's
|
Beta Was this translation helpful? Give feedback.
Um, there's a lot of stuff wrong here.
The paragraph on hash routing is the only correct thing, and is probably the cause of your problems. See WXTs docs: https://wxt.dev/guide/essentials/frontend-frameworks.html#configuring-routers
Should not be necessary, all the router libraries should work just fine in hash mode.
WXT doesn't have a
defineRoute
util, and the example doesn't even use it. Theroutes
config in the example doesn't exist either.