【发布时间】:2016-08-21 21:43:48
【问题描述】:
我有一个像 /user/3 这样的网址,我在其中发出 http 请求以获取用户信息。
如果我移动到/user/6,我将发出另一个 http 请求来获取此用户数据。
我的问题是当我点击浏览器后退按钮时,url 移回/user/3,但它仍然显示 user 6 信息。
我该怎么做?是否有可能让我的旧模型回来?还是我必须再次发出 http 请求才能获取 user 3。
我的urlUpdate 看起来像这样:
urlUpdate : Result String Route -> Model -> ( Model, Cmd Msg )
urlUpdate result model =
let
currentRoute =
Routing.routeFromResult result
in
( { model | route = currentRoute }, Cmd.none )
我有点迷茫,我不知道在哪里做这个。
如果不清楚,我想在用户单击浏览器后退按钮以获取旧网址然后发出 http 请求以再次获取此用户信息时“捕捉”一个事件。
我使用elm-navigation 包。
我已尝试在我的urlUpdate 中执行此操作:
urlUpdate : Result String Route -> Model -> ( Model, Cmd Msg )
urlUpdate result model =
let
currentRoute =
Routing.routeFromResult result
command =
case currentRoute of
Routing.HomeRoute ->
getUsers
Routing.userRoute id ->
getUser id
Routing.NotFoundRoute ->
Cmd.none
in
( { model | route = currentRoute }, command )
这和我的 init 函数是一样的。它不起作用,因为它使无限循环执行urlUpdate
【问题讨论】:
-
你用的是哪个路由包?
-
我使用榆树导航。我已经更新了我的问题
标签: http navigation history back-button elm