首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >榆树导航跳过导航

榆树导航跳过导航
EN

Stack Overflow用户
提问于 2018-08-28 21:33:35
回答 1查看 66关注 0票数 0

我在浏览器中使用elm时遇到了问题。当我导航到某个页面/事物/后缀列表时发生错误,该列表闪烁,然后被传递到路径/home。使用我的浏览器后退按钮,我可以访问/thing/stufflist页面,没有任何问题。

/thing是关于事物的主页,然后它在/ thing /xxx上有相等的制表符。

我在elm导航中设置了以下路由:

代码语言:javascript
复制
        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 model

ThingMain.page是

代码语言:javascript
复制
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:

代码语言:javascript
复制
stuffsView : List Stuff.Stuff -> Html Msg
stuffsView stuffs =
    div [class "dialog-large"][
        div [class "list"][
            renderStuffList stuffs
        ]
    ]

使用此方法呈现列表:

代码语言:javascript
复制
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" ]

并被输入到这个一般的页面方法中:

代码语言:javascript
复制
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选项卡。如前所述,我甚至可以浏览和查看我的“没有东西”页面。

对我来说,这一切似乎都是(黑色的)魔法,我不知道该去哪里看?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-29 07:24:09

这个代码没有什么问题。正如我所怀疑的,这是我自己的错。

当我导航到/thing/stufflist时,我的逻辑中有一个人为错误,因为我执行一个get(ish)请求来同步数据。结果发现如果里面什么都没有的话,我就没有得到一份名单。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52066477

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档