flutterurihashtagflutter-go-routergorouter

Flutter web - go_router - read value after hash #


Given the url: /path#someValue I would like to get the value after #, which is exactly the someValue.

GoRoute(path: 'path', pageBuilder: (context, state) {
   // I need to get: `someValue` here
}),

I am using GoRouter and setUrlStrategy(PathUrlStrategy());

It doesn't seem that someValue is present anywhere in the state.

state.fullPath contains: /path.

It seems like the hash value gets stripped immediately.

Is there any way to get the proper value after #?


Solution

  • I assume it is on the web so it is so you can use:

    import 'dart:html' as html;
    
    GoRoute(path: 'path', pageBuilder: (context, state) {
      String valorHash = html.window.location.hash;
      valorHash = valorHash.startsWith('#') ? valorHash.substring(1) : valorHash;
    
    }),