我在浏览器中使用elm时遇到了问题。当我导航到某个页面/事物/后缀列表时发生错误,该列表闪烁,然后被传递到路径/home。使用我的浏览器后退按钮,我可以访问/thing/stufflist页面,没有任何问题。
/thing是关于事物的主页,然后它在/ thing /xxx上有相等的制表符。
我在elm导航中设置了以下路由:
case routePath of
DefaultRoute ->
notFoundPage model
HomeRoute ->
homePage model
...
ThingTab id page ->
case String.toInt id of
Ok thingId ->
ThingMain.page thingId model page
Err error ->
ThingMain.page 0 model page
NotFoundRoute ->
notFoundPage modelThingMain.page是
page : Int -> Model -> String -> Html Msg
page thingId model page =
let
maybeThing =
model.thingList
|> List.filter (\thing -> thing.id == thingId)
|> List.head
in
case maybeThing of
Just thing ->
case page of
"info" ->
thingView thing (thingInfoView thing)
"stuffs" ->
let
stuffs =
model.stuffList
|> List.filter (\stuff -> stuff.ting.id == thingId)
in
thingView thing (stuffsView stuffs)
_ ->
Error.notFoundPage model
Nothing ->
Error.notFoundPage model 这个suffsView:
stuffsView : List Stuff.Stuff -> Html Msg
stuffsView stuffs =
div [class "dialog-large"][
div [class "list"][
renderStuffList stuffs
]
]使用此方法呈现列表:
renderStuffList : List Stuff.Stuff -> Html Msg
renderStuffList stuffs =
if List.isEmpty stuffs then
text "No stuff"
else
stuffs
|> List.map ( \stuff -> listStuff stuff )
|> ol [ class "stuff-list" ]并被输入到这个一般的页面方法中:
thingView : Thing.Thing -> Html Msg -> Html Msg
thingView thing tabContent =
div [class "mr-main flex-column flex-start"][
h4 [][ text (thing.name) ]
, tabContent
,div [class "dialog-large split-choice"][
button [class "input", onClick (Msg.Navigate("thing/" ++ toString thing.id )) ][
text ("Info")
]
,button [class "input", onClick (Msg.PostAndNavigate (stuffListRequest thing.id)) ][
text ("Stuffs")
]
]
,div [class "dialog-large split-choice"][
button [class "input half-width", onClick ( Msg.Navigate("home") ) ][
text ("Home")
]
]
]在所有情况下,它都可以正常工作,除非它获得了一个空列表的stufflist选项卡。如前所述,我甚至可以浏览和查看我的“没有东西”页面。
对我来说,这一切似乎都是(黑色的)魔法,我不知道该去哪里看?
发布于 2018-08-29 07:24:09
这个代码没有什么问题。正如我所怀疑的,这是我自己的错。
当我导航到/thing/stufflist时,我的逻辑中有一个人为错误,因为我执行一个get(ish)请求来同步数据。结果发现如果里面什么都没有的话,我就没有得到一份名单。
https://stackoverflow.com/questions/52066477
复制相似问题