@@ -53,6 +53,7 @@ module Obelisk.Route.Frontend
5353 , runRouteToUrlT
5454 , mapRouteToUrlT
5555 , routeLink
56+ , routeLinkDynAttr
5657 , dynRouteLink
5758 , adaptedUriPath
5859 , setAdaptedUriPath
@@ -74,6 +75,7 @@ import Control.Monad.Trans.Control
7475import Data.Coerce
7576import Data.Dependent.Sum (DSum (..))
7677import Data.GADT.Compare
78+import Data.Map (Map)
7779import Data.Monoid
7880import Data.Proxy
7981import Data.Text (Text)
@@ -526,9 +528,7 @@ routeLink r w = do
526528 setRoute $ r <$ domEvent Click e
527529 return a
528530
529−-- | A link widget that, when clicked, sets the route to current value of the
530−-- provided dynamic route. In non-javascript contexts the value of the dynamic post
531−-- build is used so the link still works like 'routeLink'.
531+-- | Like 'routeLinkDynAttr' but without custom attributes.
532532dynRouteLink
533533 :: forall t m a route.
534534 ( DomBuilder t m
@@ -537,11 +537,27 @@ dynRouteLink
537537 , SetRoute t (R route) m
538538 )
539539 => Dynamic t (R route) -- ^ Target route
540− -> m a -- ^ Child widget
540+ -> m a -- ^ Child widget of the @a@ element
541+ -> m a
542+dynRouteLink = routeLinkDynAttr mempty
543+
544+-- | An @a@-tag link widget that, when clicked, sets the route to current value of the
545+-- provided dynamic route. In non-JavaScript contexts the value of the dynamic post
546+-- build is used so the link still works like 'routeLink'.
547+routeLinkDynAttr
548+ :: forall t m a route.
549+ ( DomBuilder t m
550+ , PostBuild t m
551+ , RouteToUrl (R route) m
552+ , SetRoute t (R route) m
553+ )
554+ => Dynamic t (Map AttributeName Text) -- ^ Attributes for @a@ element. Note that if @href@ is present it will be ignored
555+ -> Dynamic t (R route) -- ^ Target route
556+ -> m a -- ^ Child widget of the @a@ element
541557 -> m a
542−dynRouteLink dr w = do
558+routeLinkDynAttr dAttr dr w = do
543559 enc <- askRouteToUrl
544− er <- dynamicAttributesToModifyAttributes $ ("href" =:) . enc <$> dr
560+ er <- dynamicAttributesToModifyAttributes $ zipDynWith (<>) (("href" =:) . enc <$> dr) dAttr
545561 let cfg = (def :: ElementConfig EventResult t (DomBuilderSpace m))
546562 & elementConfig_eventSpec %~ addEventSpecFlags (Proxy :: Proxy (DomBuilderSpace m)) Click (\_ -> preventDefault)
547563 & elementConfig_modifyAttributes .~ er