I know that base_href can be configured with below method.
command
flutter build web --base-href "/path/"
or
index.html
<base href="/path/">
ref: Setting base-href on build Flutter Web
How to get this information(/path/
) in my Dart code?
Example:
--base-href "/foo/"
URL: http://localhost:8080/foo/some-route
I want: /foo/
Uri.base.path: /foo/some-route
2
Answers
Uri.base
says:I am not sure we can get this from the
uri
directly. You could try load the html and get thehref
attribute from thebase
tag. The below snippet shows how to do that:We get the base tags, read the first one and get the href attribute. Where it is not available we return null. However, we should always have this available as it is always set as
<base href="$FLUTTER_BASE_HREF">
to allow one pass thebase href
as an arg.