All Projects → frzi → Swiftuirouter

frzi / Swiftuirouter

Licence: mit
Routing in SwiftUI

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swiftuirouter

go router
The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
Stars: ✭ 380 (+57.02%)
Mutual labels:  router, navigation, routing
Router
🛣 Simple Navigation for iOS
Stars: ✭ 438 (+80.99%)
Mutual labels:  router, routing, navigation
Corenavigation
📱📲 Navigate between view controllers with ease. 💫 🔜 More stable version (written in Swift 5) coming soon.
Stars: ✭ 69 (-71.49%)
Mutual labels:  router, routing, navigation
Router
Router implementation for fasthttp
Stars: ✭ 234 (-3.31%)
Mutual labels:  router, routing
Redux Saga Router
A router for Redux Saga
Stars: ✭ 153 (-36.78%)
Mutual labels:  router, navigation
Redux Tower
Saga powered routing engine for Redux app.
Stars: ✭ 155 (-35.95%)
Mutual labels:  router, routing
Bsdrp
BSD Router Project
Stars: ✭ 126 (-47.93%)
Mutual labels:  router, routing
React Router Native Stack
A stack navigation component for react-router-native
Stars: ✭ 171 (-29.34%)
Mutual labels:  router, navigation
Rayo.js
Micro framework for Node.js
Stars: ✭ 170 (-29.75%)
Mutual labels:  router, routing
Klein.php
A fast & flexible router
Stars: ✭ 2,622 (+983.47%)
Mutual labels:  router, routing
Next Routes
Universal dynamic routes for Next.js
Stars: ✭ 2,354 (+872.73%)
Mutual labels:  router, routing
Nextjs Dynamic Routes
[Deprecated] Super simple way to create dynamic routes with Next.js
Stars: ✭ 145 (-40.08%)
Mutual labels:  router, routing
Grip
The microframework for writing powerful web applications.
Stars: ✭ 137 (-43.39%)
Mutual labels:  router, routing
Router
⚡️ A lightning fast HTTP router
Stars: ✭ 158 (-34.71%)
Mutual labels:  router, routing
Router5
Flexible and powerful universal routing solution
Stars: ✭ 1,704 (+604.13%)
Mutual labels:  router, routing
Flow builder
Flutter Flows made easy! A Flutter package which simplifies flows with a flexible, declarative API.
Stars: ✭ 169 (-30.17%)
Mutual labels:  router, routing
Arouter
💪 A framework for assisting in the renovation of Android componentization (帮助 Android App 进行组件化改造的路由框架)
Stars: ✭ 13,587 (+5514.46%)
Mutual labels:  router, navigation
Ui Router
The de-facto solution to flexible routing with nested views in AngularJS
Stars: ✭ 13,738 (+5576.86%)
Mutual labels:  router, routing
Marshroute
Marshroute is an iOS Library for making your Routers simple but extremely powerful
Stars: ✭ 208 (-14.05%)
Mutual labels:  router, navigation
Universal Router
A simple middleware-style router for isomorphic JavaScript web apps
Stars: ✭ 1,598 (+560.33%)
Mutual labels:  router, routing

SwiftUI Router

Merely a proof of concept for now.

SwiftUI Swift Xcode MIT

Inspired by React Router, SwiftUI Router allows you to program (relatively) easy navigation in your app, much like a website, without the hassle of NavigationView and NavigationLink. SwiftUI Router borrows the following objects from React Router: Link, Redirect, Route, Router and Switch. Their behaviours should be similar to that of React Router.

Note: This project is very much a prototype/proof-of-concept. There are an unreasonable amount of kinks in the code and some basic features missing.

demo

Router (entry)

Router {
    RootView()
}

The Router view initiates a routing environment. Wrap your entire app (or at least, the part that needs navigation) in a Router.

Link

Link(to: "/my/path") {
    Text("Go to next page")
}

Wrapper around a Button view to easily navigate to another path.

Redirect

Redirect(to: "/notfound", replace: true)

When rendered, will redirect instantly to the given path. Set replace: true to prevent the redirect to be added to the history stack.

Route

Route(path: "/home", exact: false) {
    HomeView()
}

Route(path: "/news/:id/:readingMode?", exact: true) { route in
    NewsItemView(id: route.parameters.id, readingMode: route.parameters.readingMode)
}

Will only render its children when the environment's path matches that of the Route. exact requires the environment path and route path to match exactly. If false, the route will also render if the environment path is e.g. "/home/and/anything/deeper".

Parameters

The path may contain one or multiple (optional) parameters. These parameters are parsed to a dictionary, accessible via the optional RouteData object's .parameters property. The RouteData object is passed along into the Route's content.

Parameters are marked with a colon (:) in the path, followed by the parameter name. To make the parameter optional, place a question mark (?) behind the parameter's name.

A parameter's value is always of type String.

Switch

Switch {
    Route(path: "/list/details") { _ in 
        DetailsView()
    }

    Route(path: "/list/:style?") { props in 
        ListView(style: props.parameters.style)
    }

    Route {
        HomeView()
    }
}

The Switch view will only render the first matching Route view. This will allow you to render fallback routes. Note: due to the @ViewBuilder limit, only 10 direct ancestor Routes are possible.

HistoryData

@EnvironmentObject private var history: HistoryData

The HistoryData Environment Object contains methods to navigate and can be accessed inside a Router.

path: String

The current environment path. (Computed value)

go(to: String, replace: Bool = false)

Perform a navigation to a new path. Set replace to true to prevent the navigation from being added to the history stack.

goBack(count: Int = 1), goForward(count: Int = 1)

Go back or forward. count is clamped and will prevent from going out of bounds.

canGoBack: Bool, canGoForward: Bool

Returns whether you can go back or forward.


Todo

  • Allow for (optional) parameters in paths.
  • Fix history stack having some odd behaviour when returning to the root.
  • Limit the Switch view only to Route ancestors?
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].