Contents

m1guelpf/ziggy-vapor

> A better way to organize your routes.

Getting started πŸš€

Import Ziggy in your configure.swift file, then call the setup method:

// Sources/App/configure.swift
import Ziggy

// configures your application
public func configure(_ app: Application) async throws {
    // ...

    app.ziggy.setup()

    // ...
}

Then, on your routes.swift file (or wherever you define your routes), you can chain the name method to your routes to give them a name:

// Sources/App/routes.swift
import Vapor
import Ziggy

public func routes(_ app: Application) throws {
    app.get { req in
        return req.view.render("dashboard")
    }.name("dashboard")

    // ...
}

You can then use the app.route (or req.route) function to generate URLs for your routes:

let url = app.route("home") // /dashboard
let edit_user = req.route("users.edit", 1) // /users/1/edit

return req.redirect(route: "user.profile", "m1guelpf") // Redirects to /@m1guelpf

You can also access the route function on your frontend, by adding the routes tag to your HTML template and installing the ziggy-js package:

<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8">
        <link rel="stylesheet" href="/app.css" />
        <script type="module" src="/app.js"></script>

		#routes()
	</head>

	<body>
		<!-- ... -->
	</body>
</html>

πŸ“„ License

This package is open-sourced software licensed under the MIT license

Package Metadata

Repository: m1guelpf/ziggy-vapor

Default branch: main

README: README.md