Skip to content
Flow-UILive
On this page

Deep linking through host handlers

Flow-UI does not ship a router. A deeplink action is data. Your app’s handler decides NavigationStack, tabs, or an external URL.

Ayush MishraPublished 6 min read

Flow-UI does not ship a router. A deeplink action is data. Your app’s handler decides NavigationStack, tabs, or an external URL. The package delivers ActionData. It does not pick UIKit versus SwiftUI navigation, and it does not parse app:// itself.

That absence is the feature. Hosts already have a coordinator, a tab bar, or a split view. A framework router would fight it. The FAQ says the same in one paragraph: How do deeplinks work?. Server driven navigation with actions covered the built-in types (toast, dismiss, refresh_page, plus sheet and api). This article is the host type those built-ins refuse to become.

There is no router in the package#

Search the sources for a NavigationPath owner, a URL parser, or a route table. You will not find one that widgets call. ActionDispatcher’s documentation states deeplinks are absent on purpose and shows the registration line:

DeeplinkHandler.swiftswift
struct DeeplinkHandler: ActionHandler {
    struct Payload: Decodable { let url: String }
 
    func handle(_ action: ActionData, context: ActionContext) async -> Bool {
        guard action.type == "deeplink",
              let payload = try? action.payload(Payload.self) else { return false }
        await router.open(payload.url)
        return true
    }
}

router here is your type. It might push a FlowPageView for another page id. It might select a tab. It might call UIApplication.shared.open. Flow-UI does not know.

swift
dispatcher.register(DeeplinkHandler())

Register after ActionDispatcher() so the handler sits at the newest end of the chain. Return false when type is not deeplink so toast and dismiss still run. Return true once you have claimed the type, even if the URL is bad, if you do not want a later handler to treat it as unhandled. Match the toast handler’s habit: claim the type, then fail visibly in debug if the payload is wrong.

Relay is not a router either#

FlowActionRelay forwards (ActionData, widgetID) into the dispatcher. The default relay is inert for previews. FlowPageView installs a relay that builds ActionContext with the PageStore and FlowPresenter. Custom containers that render WidgetRowView inherit that environment. You do not route in the relay. You only pipe.

If a preview tap does nothing, you used the inert relay. That is expected. Hook a real dispatcher when you are testing navigation.

What the JSON should look like#

A typical envelope tap:

json
"actions": {
  "tap": { "type": "deeplink", "url": "app://orders/123" }
}

The key next to type is yours. url is the obvious one. Some hosts send page_id, tab, and url together and let the handler decide. ActionData.raw is the whole object. Decode a struct that matches what you documented with the backend. Do not wait for Flow-UI to bless the keys.

Banner’s starter comments show a deeplink example. The starter widget still just dispatches. It does not open the URL. If you never registered a handler, debug logs show handledBy: nil.

Built-ins versus destinations#

Use open_bottom_sheet when the destination is more widgets on this page. Use api when the destination is a mutation of this page. Use refresh_page when this document should reload. Use dismiss when this sheet or this hosting page should close. Use deeplink (or open_url, or push_page, names you own) when the user should leave this page’s store.

Mixing them is how you get double navigation: a handler that pushes and a sheet that also presents. Pick one type per tap.

Wiring the host#

Create the dispatcher yourself when you need host types. FlowPageView(store:dispatcher:) accepts it. Omitting the dispatcher uses built-ins only.

  1. let dispatcher = ActionDispatcher() (built-ins on).
  2. dispatcher.register(DeeplinkHandler()).
  3. Pass the dispatcher into FlowPageView or FlowHostingController.
  4. In the handler, call into the same navigation object the rest of the app uses.

UIKit hosts that push FlowHostingController already have a UINavigationController. The handler can pushViewController another hosting controller with a new PageStore(pageID:loader:registry:). SwiftUI hosts can write to a NavigationPath they own outside FlowPageView. Tab hosts can set selectedTab. Universal links that arrive from the system can call the same router.open the handler uses, so JSON taps and OS taps converge.

Cancellation and teardown#

ActionDispatcher.cancelInFlight() exists so a leaving page does not complete an api call against a gone store. Deeplink handlers that only push synchronously are less sensitive. If your handler awaits a network lookup before pushing, check Task.isCancelled and do not push after teardown. The dispatcher cancels those tasks when the host asks.

Do not store PageStore strongly in the handler. ActionContext.pageStore is weak. A deeplink that needs the current page id can read pageStore?.pageID at dispatch time and then talk only to your router.

Patterns that fight the seam#

Parsing the URL inside a WidgetView and calling openURL skips the dispatcher, skips debug logs, and skips override. Two widgets will copy two slightly different parsers.

Registering a handler that returns true for every action.type disables built-ins. Guard on the string.

Sending deeplink for “show a toast” because the web team named everything a link. Use toast.

Sending deeplink to the same page id the user is already on, hoping for a refresh. Use refresh_page.

Inventing a Flow-UI route table in JSON ({"type":"navigate","route":"home.profile.settings"}) and then asking the package to interpret it. That is a router. Keep it in the host if you truly want it. The package will not grow one.

Testing handlers#

Unit test handle with an ActionData fixture and a fake router. You do not need a PageStore for a pure navigation handler. UI tests should tap a widget whose JSON you control and assert the host navigation changed. If the tap only works in the full app because the playground has no handler, that is the same seam: playgrounds that need deeplinks must register one too.

One handler, many entry points#

JSON taps are not the only way a URL arrives. Universal links, Spotlight, push payloads, and App Intents all want the same destination. Point every one of those at router.open. The ActionHandler becomes a thin adapter from ActionData to that function. If you implement navigation only inside the handler, push notifications will invent a second path that drifts.

Pass pageID when the JSON has it. Pass a URL when the JSON has it. Do not require both. A backend that only knows app://orders/123 should not also have to invent a Flow-UI page id. A backend that only knows page_id: "pdp_sku" should not have to mint a URL. Your router already maps both.

External https:// links belong in the same handler if the type is still deeplink, or in a second type (open_url) if you want App Transport and in-app Safari to be obvious in logs. Two types are fine. Two widgets that call UIApplication.shared.open are not.

When the destination is another Flow-UI page, construct a new PageStore with the same PageLoader and registry, then push FlowPageView or FlowHostingController. Reuse the dispatcher so toast still works on the destination. Do not share a PageStore across two pages. One store is one document.

Where this sits#

Server driven navigation with actions is the built-in chain. How to implement SDUI on iOS listed “register deeplink ActionHandler” on the iOS checklist. FAQ is the short answer. Native destinations stay native: a pushed FlowPageView is still SwiftUI, which matches native SDUI in SwiftUI.

Data in, host navigation out. No router to delete later.

The Flow-UI mark: two nodes joined through a filled centre

Register a handler. Forward the URL. Keep the router you already paid for.

More on the blog.

Read the source

Flow-UI is MIT licensed. The schema, renderer and starter widgets live on GitHub.

GitHub

Get started with Flow-UI

Install the Swift package, register a widget, and render a page from JSON.

Get started