You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@shovelmn12 Currently i do the following stuff to make it work:
Give RouteInformationParser its custom parse which returns the full uri including query parameters.
Give WouterRouterDelegate a custom matcher that just matches based on path and with prefix = false + listening to currentConfguration and add it to a BehaviorSubject.
Using flutter_hooks to subscribe and rebuild UI on BehaviorSubject-Change via useQueryParameters.
import'package:rxdart/rxdart.dart';
import'package:flutter_hooks/flutter_hooks.dart';
import'package:wouter/wouter.dart'as w;
classWouterRouterDelegateextends w.WouterRouterDelegate {
WouterRouterDelegate({
requiredsuper.initial,
requiredsuper.builder,
}) :super(matcher: _routerDelegateMatcher) {
addListener(() {
final uri =Uri.parse(currentConfiguration);
_queryParametersSubject.add(uri.queryParameters);
print({
'path': currentConfiguration,
'queryParameters': uri.queryParameters,
});
});
}
}
// Override the default cached Regexp matcher to handle query parameters.
w.PathMatcher_routerDelegateMatcher() {
// Create a RegExp builder that caches compiled regular expressions.final regexpBuilder = w.cacheRegexpBuilder(w.pathToRegexp);
// Return a PathMatcher that caches (path, pattern, prefix) lookups.return w.cache(
(String path, String pattern, {bool prefix =true}) => w.regexpPathMatcher(
Uri.parse(path).path,
pattern,
regexpBuilder: regexpBuilder, // Uses the cached RegExp builder
prefix:false,
),
);
}
final routeInformationParser = w.WouterRouteInformationParser(
parse: (context, routeInformation) => routeInformation.uri.toString(),
);
final _queryParametersSubject =BehaviorSubject<Map<String, String>>.seeded({});
Map<String, String> useQueryParameters() {
final snapshot =useStream(_queryParametersSubject.stream);
return snapshot.data ?? {};
}
@shovelmn12 Okay and then just matching via regex. E.g /a:query(|\?.*) should match both /a and /a?foo=1&bar=cool&.... And inside widget i could just parse the uri and get the query params. Is that how its intended?
Activity
jtdLab commentedon Apr 6, 2026
@shovelmn12 Currently i do the following stuff to make it work:
RouteInformationParserits customparsewhich returns the full uri including query parameters.WouterRouterDelegatea custommatcherthat just matches based onpathand withprefix = false+ listening tocurrentConfgurationand add it to aBehaviorSubject.flutter_hooksto subscribe and rebuild UI onBehaviorSubject-Change viauseQueryParameters.shovelmn12 commentedon Apr 7, 2026
@jtdLab can you elaborate on what's exactly not working and provide an example? last I checked it worked ...
jtdLab commentedon Apr 7, 2026
@shovelmn12
foo?number=1path matcher does not match the path with query paramswouter/packages/wouter/lib/src/route_information.dart
Lines 67 to 84 in 5360e52
jtdLab commentedon Apr 7, 2026
@shovelmn12 Maybe i am missing how its intended to get query params with wouter. Could u give me the intended way?
shovelmn12 commentedon Apr 7, 2026
I think we can actually just pass the full uri ... so it will return "users/123?tab=profile#details" from the example and just "/users/123"....
jtdLab commentedon Apr 7, 2026
@shovelmn12 Okay and then just matching via regex. E.g
/a:query(|\?.*)should match both/aand/a?foo=1&bar=cool&.... And inside widget i could just parse the uri and get the query params. Is that how its intended?shovelmn12 commentedon Apr 7, 2026
I need to check the matcher library I think it works for query params as well ... So that should solve it