mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-28 14:34:18 +03:00
Add Route.link and Route.toLink helpers.
This commit is contained in:
parent
075a886adf
commit
33a10ede33
@ -195,17 +195,13 @@ head staticPayload =
|
|||||||
|
|
||||||
link : Route.Route -> List (Attribute msg) -> List (Html msg) -> Html msg
|
link : Route.Route -> List (Attribute msg) -> List (Html msg) -> Html msg
|
||||||
link route attrs children =
|
link route attrs children =
|
||||||
a
|
Route.toLink
|
||||||
(Attr.href
|
(\anchorAttrs ->
|
||||||
("/"
|
a
|
||||||
++ (Route.routeToPath (Just route)
|
(List.map Attr.fromUnstyled anchorAttrs ++ attrs)
|
||||||
|> String.join "/"
|
children
|
||||||
)
|
|
||||||
)
|
|
||||||
:: Attr.attribute "elm-pages:prefetch" ""
|
|
||||||
:: attrs
|
|
||||||
)
|
)
|
||||||
children
|
route
|
||||||
|
|
||||||
|
|
||||||
blogCard : ( Route, Article.ArticleMetadata ) -> Html msg
|
blogCard : ( Route, Article.ArticleMetadata ) -> Html msg
|
||||||
|
@ -494,8 +494,9 @@ mapBoth : (a -> b) -> (c -> d) -> ( a, c, e ) -> ( b, d, e )
|
|||||||
mapBoth fnA fnB ( a, b, c ) =
|
mapBoth fnA fnB ( a, b, c ) =
|
||||||
( fnA a, fnB b, c )
|
( fnA a, fnB b, c )
|
||||||
`,
|
`,
|
||||||
routesModule: `module Route exposing (..)
|
routesModule: `module Route exposing (Route(..), link, matchers, routeToPath, toLink, urlToRoute)
|
||||||
|
import Html exposing (Attribute, Html)
|
||||||
|
import Html.Attributes as Attr
|
||||||
import Router
|
import Router
|
||||||
|
|
||||||
|
|
||||||
@ -555,6 +556,24 @@ routeToPath maybeRoute =
|
|||||||
})} ]`
|
})} ]`
|
||||||
)
|
)
|
||||||
.join("\n ")}
|
.join("\n ")}
|
||||||
|
|
||||||
|
toLink : (List (Attribute msg) -> tag) -> Route -> tag
|
||||||
|
toLink toAnchorTag route =
|
||||||
|
toAnchorTag
|
||||||
|
[ Attr.href ("/" ++ (routeToPath (Just route) |> String.join "/"))
|
||||||
|
, Attr.attribute "elm-pages:prefetch" ""
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
link : Route -> List (Attribute msg) -> List (Html msg) -> Html msg
|
||||||
|
link route attributes children =
|
||||||
|
toLink
|
||||||
|
(\\anchorAttrs ->
|
||||||
|
Html.a
|
||||||
|
(anchorAttrs ++ attributes)
|
||||||
|
children
|
||||||
|
)
|
||||||
|
route
|
||||||
`,
|
`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user