我正在尝试使用带有elm-router的elm创建一个前端,以便管理路由。
我有这个主文件:
-- Main.elm
import Router exposing (Route, match, (:->))
import History exposing (path)
import Routing as Routing exposing (route)
import Signal exposing ((<~))
import Html exposing (Html)
import Signal exposing (Mailbox, mailbox, Signal)
import Task exposing (Task)
import Test as Test exposing (pathChangeMailbox)
main : Signal Html
main = route <~ path
port runTask : Signal (Task error())
port runTask =
pathChangeMailbox.signal
此模块处理邮箱。我可以逐页使用邮箱,但它很难看,所以我尝试制作一个模块来处理所有常用代码。
module Test where
import Signal exposing (Mailbox, mailbox, Signal)
import Task exposing (Task)
pathChangeMailbox : Mailbox (Task error ())
pathChangeMailbox = mailbox (Task.succeed())
我还有一个模块Routing
来列出路线并将行动与他们联系起来。
这是处理菜单的模块,以及导航。
module Menu where
import Html exposing (a, text, Html, div)
import Html.Events exposing (onClick)
import Task exposing (Task)
import History exposing (setPath)
import Test as Test exposing (pathChangeMailbox)
display : String -> Html
display _ =
div []
[
a []
[ onClick Test.pathChangeMailbox.address (setPath "/CV.elm") ]
[ text "Mon CV" ]
]
当我尝试运行程序时出现以下错误:
Error in .\src\Menu.elm:
Error on line 14, column 22 to 47:
Could not find variable 'Test.pathChangeMailbox.address'.
Looks like the prefix 'Test.pathChangeMailbox' is not in scope. Is it spelled correctly?
Is it imported correctly?
You can read about how imports work at the following address:
你有没有,为什么即使我导入Test
模块,仍然说Test.pathChangeMailbox
不在范围内?
编辑:添加Routing.elm
module Routing where
import Html exposing (Html, div, text, br)
import Signal exposing (Mailbox, mailbox, Signal)
import Task exposing (Task)
import Router exposing (match, (:->), Route)
-- Import displays
import CV as CV exposing (display)
import Home as Home exposing (display)
route : Route Html
route = match
[
"/src/Main.elm" :-> Home.display
, "/CV.elm" :-> CV.display
] display404
display404 : String -> Html
display404 url =
div []
[
text "Erreur 404"
, br [] []
, text ("url : " ++ url ++ " not found.")
]
答案 0 :(得分:2)
我认为你在这里发现了一个错误。你应该 file an issue。
编辑:good job :)链接摘要:问题来自混合用于限定模块访问和记录访问的.
。
这是现在的解决方法,导入名称不合格并使用不合格。注意我还删除了额外的[]
:
@@ -4,13 +4,13 @@ import Html exposing (a, text, Html, div)
import Html.Events exposing (onClick)
import Task exposing (Task)
import History exposing (setPath)
import Test as Test exposing (pathChangeMailbox)
display : String -> Html
display _ =
div []
[
- a []
- [ onClick Test.pathChangeMailbox.address (setPath "/CV.elm") ]
+ a
+ [ onClick pathChangeMailbox.address (setPath "/CV.elm") ]
[ text "Mon CV" ]
]
(Menu.elm)