将URL参数传递到飘动的单页应用程序
我写了一个颤音的水疗中心。该应用的URL看起来像这样:
https://acmecorp.web.app.app/#/
并且访问的任何页面都不显示更新的URL(因为我不希望人们在应用中共享单个页面)。
但是,当用户被定向到网站时,我想捕获一个可选参数(用户ID),类似的内容:
https://acmecorp.web.app/#/uid 或
?一旦通过开始页面捕获UID并将其设置为局部变量,我就不需要在URL栏中生存。
我尝试使用html.window.location.href
和对此的变体尝试捕获UID,这是不成功的。我了解磅标志向URL片段发出信号,因此剥离后的东西,但是即使使用参数的位置也没有帮助,例如https://acmecorp.web.web.app.uid=test/#/ < /code>或
https://acmecorp.web.app/?uid=test#/
。
我还尝试在main.dart
中与Gorouter弄乱,
routes: <GoRoute>[
GoRoute(
path: '/',
builder: (context, state) => StartPageWidget(
uid: state.queryParams['did'],
),
),
],
);
因为我的成功率有限,因为当我尝试导航到其他页面时,它似乎会破坏路由。
这似乎是超级简单的事情,我不确定我缺少什么。我是一名数据科学家,非常新鲜!
感谢您的帮助!
I have written a flutter SPA. The URL for the app looks like this:
and any pages visited do not show an updated URL (because I don't want people to share individual pages within the app).
However, I would like to capture an optional parameter (user id) when users are directed to the site, something like this:
https://acmecorp.web.app/#/uid or https://acmecorp.web.app/#/?uid=test
. Once the uid is captured by the start page and set as a local variable, I don't need this uid to survive in the URL bar.
I have tried using html.window.location.href
and variations of this to try to capture the uid, which was unsuccessful. I understand that the pound sign signals a URL fragment so things after it are stripped, but even playing with the position of the parameters has not helped e.g. https://acmecorp.web.app?uid=test/#/
or https://acmecorp.web.app/?uid=test#/
.
I also tried messing around with gorouter in main.dart
routes: <GoRoute>[
GoRoute(
path: '/',
builder: (context, state) => StartPageWidget(
uid: state.queryParams['did'],
),
),
],
);
with limited success, as I then have the problem that it seems to ruin the routing when I try to navigate to the other pages.
This seems like something super simple and I'm not sure what I'm missing. I'm a data scientist so pretty new to this!... I do recall being able to do this in angular quite easily.
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 uri.base 以捕获类似此类似的查询参数
Use Uri.base to capture query parameters like this: