Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Named routes for your Vapor app, both on Swift and on Javascript!

License

NotificationsYou must be signed in to change notification settings

m1guelpf/ziggy-vapor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A better way to organize your routes.

Swift VersionVapor VersionGitHub license

Installation

AddZiggy to the package dependencies (in yourPackage.swift file):

dependencies:[...,.package(url:"https://github.com/m1guelpf/ziggy-vapor.git", from:"1.0.0")]

as well as to your target (e.g. "App"):

targets:[....target(        name:"App",        dependencies:[..."Ziggy"...]),...]

Getting started 🚀

Import Ziggy in yourconfigure.swift file, then call thesetup method:

// Sources/App/configure.swiftimport Ziggy// configures your applicationpublicfunc configure(_ app:Application)asyncthrows{    // ...    app.ziggy.setup()    // ...}

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

// Sources/App/routes.swiftimport Vaporimport Ziggypublicfunc routes(_ app:Application)throws{    app.get{ reqinreturn req.view.render("dashboard")}.name("dashboard")    // ...}

You can then use theapp.route (orreq.route) function to generate URLs for your routes:

leturl= app.route("home") // /dashboardletedit_user= req.route("users.edit",1) // /users/1/editreturn req.redirect(route:"user.profile","m1guelpf") // Redirects to /@m1guelpf

You can also access theroute function on your frontend, by adding theroutes tag to your HTML template and installingtheziggy-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 theMIT license


[8]ページ先頭

©2009-2025 Movatter.jp