Module

Solid.Router

Package
purescript-purs-solid
Repository
arazorda/purs-solid

Paths are parsed at compile time, so a route's component receives exactly the params its path declares. Links are plain anchors (H.a { href: href @"/users/:id" { id } }); the router intercepts same-origin clicks and marks the active link with aria-current="page".

#Route Source

data Route

#RouteProps Source

type RouteProps :: Row Type -> Typetype RouteProps params = { children :: JSX, params :: Accessor (Record params) }

children is the matched child route (for a layout).

#RouteOptions Source

type RouteOptions :: Row Type -> Row Typetype RouteOptions params = (preload :: PreloadArgs params -> Effect Unit)

#PreloadArgs Source

type PreloadArgs :: Row Type -> Typetype PreloadArgs params = { intent :: String, params :: Record params }

intent is "initial", "navigate", "native" or "preload".

#route Source

route :: forall @path params. IsSymbol path => PathParams path params => (RouteProps params -> Setup JSX) -> Route

route @"/users/:id<int>/:tab?" \props -> ... (optional params are Maybe).

#routeWith Source

routeWith :: forall @path params given missing. IsSymbol path => PathParams path params => Union given missing (RouteOptions params) => Record given -> (RouteProps params -> Setup JSX) -> Route

Takes any subset of RouteOptions.

#layout Source

layout :: forall @path params. IsSymbol path => PathParams path params => (RouteProps params -> Setup JSX) -> Array Route -> Route

Render the matched child with props.children. Child paths are relative to this one.

#layoutWith Source

layoutWith :: forall @path params given missing. IsSymbol path => PathParams path params => Union given missing (RouteOptions params) => Record given -> (RouteProps params -> Setup JSX) -> Array Route -> Route

#layoutLazy Source

layoutLazy :: forall @path @name params. IsSymbol path => LazyName name => PathParams path params => (RouteProps params -> Setup JSX) -> Route

A layout whose child routes load on first match, from the module name, which exports routes :: Array Route: layoutLazy @"/admin" @"App.Admin" render.

#Router Source

data Router

#History Source

data History

#RouterOptions Source

type RouterOptions :: Row Typetype RouterOptions = (actionBase :: String, base :: String, explicitLinks :: Boolean, history :: History, preload :: Effect Unit, preloadLinks :: Boolean, scrollRestoration :: Boolean, singleFlight :: Boolean, transformUrl :: String -> String)

#browserHistory Source

#hashHistory Source

hashHistory :: forall m. MonadReactive m => m History

#memoryHistory Source

memoryHistory :: forall m. MonadReactive m => String -> m History

Starts at the given URL.

#createRouter Source

createRouter :: forall m given missing. MonadReactive m => Union given missing RouterOptions => { routes :: Array Route | given } -> m Router

The route tree is fixed. Takes routes and any subset of RouterOptions. Works in Effect or Setup.

#routerView Source

routerView :: Router -> (JSX -> Setup JSX) -> JSX

root wraps the matched route (the app shell).

#routerViewAt Source

routerViewAt :: String -> Router -> (JSX -> Setup JSX) -> JSX

For server rendering when no request event provides the URL (static rendering, tests).

#Location Source

#locationState Source

locationState :: Location -> Accessor (Maybe Json)

The state the navigation passed, if any.

#locationKey Source

locationKey :: Location -> Accessor String

Identifies the history entry.

#useIsRouting Source

useIsRouting :: Setup (Accessor Boolean)

true while a navigation (and the next route's data) is in progress.

#useMatch Source

useMatch :: forall @path params. IsSymbol path => PathParams path params => Setup (Accessor (Maybe (Record params)))

The params of path while the location matches it: useMatch @"/users/:id<int>" is an Accessor (Maybe { id :: Int }).

#LinkState Source

type LinkState = { active :: Accessor Boolean, current :: Accessor Boolean, pending :: Accessor Boolean }

active follows the pathname, including descendants. current requires an exact pathname and query match. pending marks the navigation target.

#useResolvedPath Source

useResolvedPath :: Accessor String -> Setup (Accessor (Maybe String))

Resolves a path against the current route, as an href would be.

#usePreloadRoute Source

usePreloadRoute :: Setup (String -> Effect Unit)

Loads a URL's route code and data ahead of navigating there.

#BeforeLeave Source

type BeforeLeave = { defaultPrevented :: Boolean, forceRetry :: Effect Unit, preventDefault :: Effect Unit, retry :: Effect Unit, to :: String }

A navigation away from the current route. preventDefault blocks it; retry tries it again, and forceRetry without asking the handlers.

#Navigate Source

#NavigateOptions Source

type NavigateOptions :: Row Typetype NavigateOptions = (replace :: Boolean, resolve :: Boolean, scroll :: Boolean, state :: Json)

#navigate Source

navigate :: Navigate -> String -> Effect Unit

Call from an event handler or effect.

#navigateWith Source

navigateWith :: forall given missing. Union given missing NavigateOptions => Record given -> Navigate -> String -> Effect Unit

Takes any subset of NavigateOptions.

#navigateTo Source

navigateTo :: forall @path params. IsSymbol path => PathParams path params => Navigate -> Record params -> Effect Unit

navigateTo @"/users/:id<int>" nav { id: 42 }.

#go Source

go :: Navigate -> Int -> Effect Unit

go nav (-1) is back.

Re-exports from Solid.Router.Path

#href Source

href :: forall @path params. IsSymbol path => PathParams path params => Record params -> String

Nothing optional params are left out; values are URI-encoded.