假设我配置红石如下
@app.Route("/raw/user/:id", methods: const [app.GET])
getRawUser(int id) => json_about_user_id;
当我运行服务器并转到时,/raw/user/10
我以字符串的形式获取原始 json 数据。
现在我希望能够去,比如说,/user/10
得到一个很好的表示我从中得到的这个 json /raw/user/10
。
我想到的解决方案如下:
- 第一的
- create
web/user/user.html
andweb/user/user.dart
,配置后者在index.html
被访问时运行 - 在
user.dart
监视查询参数 (user.dart?id=10
) 中,提出适当的请求并在 中显示所有内容user.html
,即
- create
var uri = Uri.parse( window.location.href );
String id = uri.queryParameters['id'];
new HttpRequest().getString(new Uri.http(SERVER,'/raw/user/${id}').toString() ).then( presentation )
这个解决方案的一个缺点是我根本没有实现/user/10
类似 url。
另一种方法是额外配置红石如下:
@app.Route("/user/:id", methods: const [app.GET]) getUser(int id) => app.redirect('/person/index.html?id=${id}');
在这种情况下,至少允许使用“/user/10”之类的网址,但这根本行不通。
我将如何正确地做到这一点?在我看来,redstone 的 git 上的 web 应用程序的例子是神秘而复杂的。
我不确定这是否必须仅与红石或飞镖有关,但我找不到任何相关内容。