{"id":13751691,"url":"https://github.com/frzi/swiftui-router","last_synced_at":"2025-12-11T23:00:43.484Z","repository":{"id":38238198,"uuid":"202872150","full_name":"frzi/swiftui-router","owner":"frzi","description":"Path-based routing in SwiftUI","archived":false,"fork":false,"pushed_at":"2024-10-09T12:16:33.000Z","size":4802,"stargazers_count":952,"open_issues_count":10,"forks_count":47,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-05-12T13:21:33.405Z","etag":null,"topics":["navigation","path","router","routing","swift","swiftui"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frzi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-17T11:25:28.000Z","updated_at":"2025-05-09T02:52:37.000Z","dependencies_parsed_at":"2022-07-12T01:31:04.165Z","dependency_job_id":"e8549dd6-edcb-49e7-ae78-d1bf3113ce01","html_url":"https://github.com/frzi/swiftui-router","commit_stats":{"total_commits":98,"total_committers":12,"mean_commits":8.166666666666666,"dds":"0.29591836734693877","last_synced_commit":"b142deddf796b38b5e43c40e6d8d6661908633b9"},"previous_names":["frzi/swiftui-router","frzi/swiftuirouter"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frzi%2Fswiftui-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frzi%2Fswiftui-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frzi%2Fswiftui-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frzi%2Fswiftui-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frzi","download_url":"https://codeload.github.com/frzi/swiftui-router/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254485065,"owners_count":22078767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["navigation","path","router","routing","swift","swiftui"],"created_at":"2024-08-03T09:00:52.312Z","updated_at":"2025-12-11T23:00:37.952Z","avatar_url":"https://github.com/frzi.png","language":"Swift","funding_links":[],"categories":["🌎 by the community","HarmonyOS"],"sub_categories":["Windows Manager"],"readme":"\u003cimg src=\"Docs/Images/logo.svg\" alt=\"SwiftUI Router\" width=\"600\"\u003e\n\n\u003e Easy and maintainable app navigation with path-based routing for SwiftUI.\n\n![SwiftUI](https://img.shields.io/github/v/release/frzi/SwiftUIRouter?style=for-the-badge)\n[![SwiftUI](https://img.shields.io/badge/SwiftUI-blue.svg?style=for-the-badge\u0026logo=swift\u0026logoColor=black)](https://developer.apple.com/xcode/swiftui)\n[![Swift](https://img.shields.io/badge/Swift-5.3-orange.svg?style=for-the-badge\u0026logo=swift)](https://swift.org)\n[![Xcode](https://img.shields.io/badge/Xcode-13-blue.svg?style=for-the-badge\u0026logo=Xcode\u0026logoColor=white)](https://developer.apple.com/xcode)\n[![MIT](https://img.shields.io/badge/license-MIT-black.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)\n\nWith **SwiftUI Router** you can power your SwiftUI app with path-based routing. By utilizing a path-based system, navigation in your app becomes more flexible and easier to maintain.\n\n\u003cbr\u003e\n\n:warning: During WWDC22 Apple introduced [`NavigationStack`](https://developer.apple.com/documentation/swiftui/navigationstack) to SwiftUI. This provides a similar workflow to **SwiftUI Router** as well as being type-safe. There are however some key differences. It is recommended to try out `NavigationStack` before using **SwiftUI Router** in your project.\n\n\u003cbr\u003e\n\n## Index\n* [Installation](#installation-)\n* [Documentation](#documentation-)\n* [Examples](#examples-)\n* [Usage](#usage-)\n* [License](#license-)\n\n## Installation 🛠\nIn Xcode add the dependency to your project via *File \u003e Add Packages \u003e Search or Enter Package URL* and use the following url:\n```\nhttps://github.com/frzi/SwiftUIRouter.git\n```\n\nOnce added, import the package in your code:\n```swift\nimport SwiftUIRouter\n```\n*Bada bing bada boom you're ready to go.*\n\n\u003cbr\u003e\n\n## Documentation 📚\n- [Animating routes](/Docs/AnimatingRoutes.md)\n- [SwiftUI Router vs NavigationStack](https://github.com/frzi/SwiftUIRouter/discussions/59)\n\n\u003cbr\u003e\n\n## Examples 👀\n- [SwiftUI Router Examples](https://github.com/frzi/SwiftUIRouter-Examples) contains:  \n  ┗ [RandomUsers](https://github.com/frzi/SwiftUIRouter-Examples/tree/main/RandomUsers)  \n  ┗ [Swiping](https://github.com/frzi/SwiftUIRouter-Examples/tree/main/Swiping)  \n  ┗ [TabViews](https://github.com/frzi/SwiftUIRouter-Examples/tree/main/TabViewRouting)\n\n\u003cbr\u003e\n\n## Usage 🚀\nBelow a quick rundown of the available views and objects and their basic features. For further details, please check out the documentation in the Swift files.\n\n### `Router`\n```swift\nRouter {\n\tRootView()\n}\n```\nThe entry of a routing environment. Wrap your entire app (or just the part that needs routing) inside a `Router`. This view will initialize all necessary environment values needed for routes.\n\n\u003cbr\u003e\n\n### `Route`\n```swift\nRoute(\"news/*\") {\n\tNewsScreen()\n}\nRoute(\"settings\") {\n\tSettingsScreen()\n}\nRoute(\"user/:id?\") { info in\n\tUserScreen(id: info.parameters[\"id\"])\n}\n```\nA view that will only render its contents if its path matches that of the environment. Use `/*` to also match deeper paths. E.g.: the path `news/*` will match the following environment paths: `/news`, `/news/latest`, `/news/article/1` etc.\n\n#### Parameters\nPaths can contain parameters (aka placeholders) that can be read individually. A parameter's name is prefixed with a colon (`:`). Additionally, a parameter can be considered optional by suffixing it with a question mark (`?`). The parameters are passed down as a `[String : String]` in an `RouteInformation` object to a `Route`'s contents.  \n**Note**: Parameters may only exist of alphanumeric characters (A-Z, a-z and 0-9) and *must* start with a letter.\n\n#### Parameter validation\n```swift\nfunc validateUserID(routeInfo: RouteInformation) -\u003e UUID? {\n\tUUID(routeInfo.parameters[\"id\"] ?? \"\")\n}\n\nRoute(\"user/:id\", validator: validateUserID) { userID in\n\tUserScreen(userID: userID)\n}\n```\nA `Route` provides an extra step for validating parameters in a path.  \n\nLet's say your `Route` has the path `/user/:id`. By default, the `:id` parameter can be *anything*. But in this case you only want valid [UUIDs](https://developer.apple.com/documentation/foundation/uuid). Using a `Route`'s `validator` argument, you're given a chance to validate (and transform) the parameter's value.  \n\nA validator is a simple function that's passed a `RouteInformation` object (containing the parameters) and returns the transformed value as an optional. The new transformed value is passed down to your view instead of the default `RouteInformation` object. If the transformed value is `nil` the `Route` will prevent rendering its contents.\n\n\u003cbr\u003e\n\n### `NavLink`\n```swift\nNavLink(to: \"/news/latest\") {\n\tText(\"Latest news\")\n}\n```\nA wrapper around a `Button` that will navigate to the given path if pressed.\n\n\u003cbr\u003e\n\n### `SwitchRoutes`\n```swift\nSwitchRoutes {\n\tRoute(\"latest\") {\n\t\tLatestNewsScreen()\n\t}\n\tRoute(\"article/:id\") { info in\n\t\tNewsArticleScreen(articleID: info.parameters[\"id\"]!)\n\t}\n\tRoute(\":unknown\") {\n\t\tErrorScreen()\n\t}\n\tRoute {\n\t\tNewsScreen()\n\t}\n}\n```\nA view that will only render the first `Route` whose path matches the environment path. This is useful if you wish to work with fallbacks. This view can give a slight performance boost as it prevents `Route`s from path matching once a previous `Route`'s path is already resolved.\n\n\u003cbr\u003e\n\n### `Navigate`\n```swift\nNavigate(to: \"/error-404\")\n```\nThis view will automatically navigate to another path once rendered. One may consider using this view in a fallback `Route` inside a `SwitchRoutes`.\n\n\u003cbr\u003e\n\n### `Navigator`\n```swift\n@EnvironmentObject var navigator: Navigator\n```\nAn environment object containg the data of the `Router`. With this object you can programmatically navigate to another path, go back in the history stack or go forward.\n\n\u003cbr\u003e\n\n### `RouteInformation`\n```swift\n@EnvironmentObject var routeInformation: RouteInformation\n```\nA lightweight object containing information of the current `Route`. A `RouteInformation` contains the relative path and a `[String : String]` with all the parsed [parameters](#parameters).  \n\nThis object is passed down by default in a `Route` to its contents. It's also accessible as an environment object.\n\n\u003cbr\u003e\n\n## License 📄\n[MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrzi%2Fswiftui-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrzi%2Fswiftui-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrzi%2Fswiftui-router/lists"}