Token导航 LogoToken导航TokenDH.com
前端设计操作浏览器github未标认证来源可访问clear审计通过

phoenix-routingPhoenix routing 前端

Agent Skill

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

总安装

499

周安装

20

GitHub Stars

142

下载量

162
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:phoenix-routing(Phoenix routing 前端)
来源仓库:https://github.com/thebushidocollective/han
仓库路径:skills/phoenix-routing
安装命令:
npx skills add https://github.com/thebushidocollective/han --skill phoenix-routing
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/thebushidocollective/han --skill phoenix-routing

简介

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。

  • 适合生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码。
  • 使用时需要结合项目现有设计系统、路由和构建方式,避免生成孤立片段。
  • 涉及页面改动时,应配合本地预览和构建检查确认视觉效果。
  • phoenix-routing 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Phoenix Routing

Phoenix routing maps incoming HTTP requests to controller actions. The router is the entry point for all web requests and determines which controller action should handle each request. Phoenix provides powerful routing macros for RESTful resources, scopes, pipelines, and verified routes.

Basic Route Declaration

Single Routes

Define individual routes using HTTP verb macros:

get "/", PageController, :home

Phoenix supports all standard HTTP verbs:

get "/users", UserController, :index
post "/users", UserController, :create
patch "/users/:id", UserController, :update
put "/users/:id", UserController, :update
delete "/users/:id", UserController, :delete

Routes with Dynamic Segments

Capture URL parameters using the :param_name syntax:

get "/hello/:messenger", HelloController, :show

The :messenger segment becomes available in the controller's params map.

Resource Routes

Basic Resource Declaration

Generate all standard RESTful routes with the resources macro:

resources "/users", UserController

This generates eight routes:

GET     /users           UserController :index
GET     /users/:id/edit  UserController :edit
GET     /users/new       UserController :new
GET     /users/:id       UserController :show
POST    /users           UserController :create
PATCH   /users/:id       UserController :update
PUT     /users/:id       UserController :update
DELETE  /users/:id       UserController :delete

Limiting Resource Routes

Use :only to generate specific routes:

resources "/users", UserController, only: [:show]
resources "/posts", PostController, only: [:index, :show]

Use :except to exclude specific routes:

resources "/users", UserController, except: [:create, :delete]

Aliasing Resources

Customize the route path helper name with :as:

resources "/users", UserController, as: :person

This generates path helpers like ~p"/person" instead of ~p"/users".

Nested Resources

Create hierarchical resource relationships:

resources "/users", UserController do
  resources "/posts", PostController
end

Generated routes include the parent resource ID:

GET     /users/:user_id/posts           PostController :index
GET     /users/:user_id/posts/:id/edit  PostController :edit
GET     /users/:user_id/posts/new       PostController :new
GET     /users/:user_id/posts/:id       PostController :show
POST    /users/:user_id/posts           PostController :create
PATCH   /users/:user_id/posts/:id       PostController :update
PUT     /users/:user_id/posts/:id       PostController :update
DELETE  /users/:user_id/posts/:id       PostController :delete

Verified Routes

Using the ~p Sigil

Phoenix provides compile-time verified routes using the ~p sigil:

# Static paths
~p"/users"
~p"/posts/new"

# Dynamic segments with variables
~p"/users/#{user_id}"
~p"/users/#{user_id}/posts/#{post_id}"

Verified Routes with Structs

Pass structs directly to generate paths:

~p"/users/#{@user}"
# Generates: "/users/42"

~p"/users/#{user}/posts/#{post}"
# Generates: "/users/42/posts/17"

Phoenix automatically extracts the ID using the Phoenix.Param protocol.

Benefits of Verified Routes

  1. Compile-time validation - Catch routing errors during compilation
  2. Refactoring safety - Route changes are caught immediately
  3. Type safety - Ensure correct parameter types
  4. URL slug support - Easy transition to slug-based URLs

Scopes

Basic Scopes

Group routes under a common path prefix:

scope "/admin", HelloWeb.Admin do
  pipe_through :browser

  resources "/users", UserController
end

Generated paths include the scope prefix:

~p"/admin/users"

Scopes with Aliases

Reduce repetition by aliasing controller modules:

scope "/", HelloWeb do
  pipe_through :browser

  get "/", PageController, :home
  resources "/posts", PostController
end

Nested Scopes

Create hierarchical route organization:

scope "/api", HelloWeb.Api, as: :api do
  pipe_through :api

  scope "/v1", V1, as: :v1 do
    resources "/users", UserController
  end

  scope "/v2", V2, as: :v2 do
    resources "/users", UserController
  end
end

Generated path helpers reflect the nesting:

~p"/api/v1/users"
~p"/api/v2/users"

Pipelines

Defining Pipelines

Pipelines group plugs that run for specific routes:

pipeline :browser do
  plug :accepts, ["html"]
  plug :fetch_session
  plug :fetch_live_flash
  plug :put_root_layout, html: {HelloWeb.Layouts, :root}
  plug :protect_from_forgery
  plug :put_secure_browser_headers
end

pipeline :api do
  plug :accepts, ["json"]
end

Applying Pipelines to Scopes

Use pipe_through to apply pipelines:

scope "/", HelloWeb do
  pipe_through :browser

  get "/", PageController, :home
  resources "/users", UserController
end

scope "/api", HelloWeb.Api do
  pipe_through :api

  resources "/users", UserController
end

Custom Plugs in Pipelines

Add application-specific plugs:

pipeline :browser do
  plug :accepts, ["html"]
  plug :fetch_session
  plug :fetch_live_flash
  plug :put_root_layout, html: {HelloWeb.Layouts, :root}
  plug :protect_from_forgery
  plug :put_secure_browser_headers
  plug HelloWeb.Plugs.Locale, "en"
end

Nesting Pipelines

Compose pipelines for complex authentication flows:

pipeline :auth do
  plug :browser
  plug :ensure_authenticated_user
  plug :ensure_user_owns_review
end

scope "/reviews", HelloWeb do
  pipe_through :auth

  resources "/", ReviewController
end

This applies the :browser pipeline first, then the authentication plugs.

Advanced Pipeline Patterns

Session Management Pipeline

Create a pipeline for session-based features:

pipeline :browser do
  plug :accepts, ["html"]
  plug :fetch_session
  plug :fetch_live_flash
  plug :put_root_layout, html: {HelloWeb.Layouts, :root}
  plug :protect_from_forgery
  plug :put_secure_browser_headers
  plug :fetch_current_scope_for_user
end

defp fetch_current_scope_for_user(conn, _opts) do
  if id = get_session(conn, :scope_id) do
    assign(conn, :current_scope, MyApp.Scope.for_id(id))
  else
    id = System.unique_integer()

    conn
    |> put_session(:scope_id, id)
    |> assign(:current_scope, MyApp.Scope.for_id(id))
  end
end

Multi-tenant Routing

Assign organization context from URL parameters:

pipeline :browser do
  plug :accepts, ["html"]
  plug :fetch_session
  plug :fetch_live_flash
  plug :put_root_layout, html: {HelloWeb.Layouts, :root}
  plug :protect_from_forgery
  plug :put_secure_browser_headers
  plug :fetch_current_scope_for_user
  plug :assign_org_to_scope
end

defp assign_org_to_scope(conn, _opts) do
  case conn.params["org"] do
    nil -> conn
    org_slug ->
      scope = conn.assigns.current_scope
      org = MyApp.Organizations.get_by_slug!(org_slug)
      assign(conn, :current_scope, Map.put(scope, :organization, org))
  end
end

Shopping Cart Pipeline

Fetch or create a cart for the current session:

pipeline :browser do
  plug :accepts, ["html"]
  plug :fetch_session
  plug :fetch_live_flash
  plug :put_root_layout, html: {HelloWeb.Layouts, :root}
  plug :protect_from_forgery
  plug :put_secure_browser_headers
  plug :fetch_current_scope_for_user
  plug :fetch_current_cart
end

alias MyApp.ShoppingCart

defp fetch_current_cart(%{assigns: %{current_scope: scope}} = conn, _opts)
    when not is_nil(scope) do
  if cart = ShoppingCart.get_cart(scope) do
    assign(conn, :cart, cart)
  else
    {:ok, new_cart} = ShoppingCart.create_cart(scope, %{})
    assign(conn, :cart, new_cart)
  end
end

defp fetch_current_cart(conn, _opts), do: conn

Forwarding

Forward to Plugs

Delegate a path prefix to another plug or application:

defmodule HelloWeb.Router do
  use HelloWeb, :router

  scope "/", HelloWeb do
    pipe_through :browser
    get "/", PageController, :home
  end

  forward "/jobs", BackgroundJob.Plug
end

All requests to /jobs/* are handled by BackgroundJob.Plug.

Common Forward Use Cases

# Admin interface
forward "/admin", HelloWeb.AdminRouter

# API documentation
forward "/api/docs", PhoenixSwagger.Plug.SwaggerUI

# Background job dashboard
forward "/jobs", Oban.Web.Router

Inspecting Routes

Using mix phx.routes

View all defined routes in your application:

mix phx.routes

Output shows HTTP verb, path, controller, and action:

GET     /                HelloWeb.PageController :home
GET     /users           HelloWeb.UserController :index
GET     /users/:id/edit  HelloWeb.UserController :edit
GET     /users/new       HelloWeb.UserController :new
GET     /users/:id       HelloWeb.UserController :show
POST    /users           HelloWeb.UserController :create
PATCH   /users/:id       HelloWeb.UserController :update
PUT     /users/:id       HelloWeb.UserController :update
DELETE  /users/:id       HelloWeb.UserController :delete

Filtering Routes

Grep for specific routes:

mix phx.routes | grep users
mix phx.routes | grep POST

Building Paths Programmatically

Static Paths

Build static paths easily:

~p"/users"
# Returns: "/users"

~p"/posts/new"
# Returns: "/posts/new"

Paths with Integer IDs

Interpolate IDs directly:

user_id = 42
post_id = 17
~p"/users/#{user_id}/posts/#{post_id}"
# Returns: "/users/42/posts/17"

Paths with Structs

Let Phoenix extract IDs from structs:

~p"/users/#{user}/posts/#{post}"
# Returns: "/users/42/posts/17"

This uses the Phoenix.Param protocol to extract the ID.

Custom Param Implementation

Implement custom URL generation for structs:

defimpl Phoenix.Param, for: MyApp.Blog.Post do
  def to_param(%{slug: slug}), do: slug
end

# Now this generates slug-based URLs:
~p"/posts/#{post}"
# Returns: "/posts/my-great-post"

Router Configuration Example

Complete Router Setup

A typical Phoenix router includes multiple pipelines and scopes:

defmodule HelloWeb.Router do
  use HelloWeb, :router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_live_flash
    plug :put_root_layout, html: {HelloWeb.Layouts, :root}
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  pipeline :api do
    plug :accepts, ["json"]
  end

  scope "/", HelloWeb do
    pipe_through :browser

    get "/", PageController, :home
    get "/hello", HelloController, :index
    get "/hello/:messenger", HelloController, :show
  end

  scope "/api/v1", HelloWeb.Api.V1, as: :api_v1 do
    pipe_through :api

    resources "/users", UserController, only: [:index, :show]
  end

  # Admin interface
  scope "/admin", HelloWeb.Admin, as: :admin do
    pipe_through [:browser, :admin_auth]

    resources "/users", UserController
    resources "/posts", PostController
  end

  # Enable LiveDashboard in development
  if Mix.env() in [:dev, :test] do
    import Phoenix.LiveDashboard.Router

    scope "/" do
      pipe_through :browser
      live_dashboard "/dashboard", metrics: HelloWeb.Telemetry
    end
  end
end

When to Use This Skill

Use this skill when you need to:

  1. Define new routes for controllers and actions
  2. Create RESTful resource routes for CRUD operations
  3. Organize routes with scopes and namespaces
  4. Build nested resource relationships
  5. Configure request processing pipelines
  6. Generate verified route paths in controllers and templates
  7. Implement API versioning with scoped routes
  8. Debug routing issues and inspect available routes
  9. Forward requests to external plugs or applications
  10. Implement custom URL slug generation
  11. Set up authentication and authorization pipelines
  12. Create multi-tenant routing architectures
  13. Build admin interfaces with separate scopes
  14. Configure different response formats (HTML, JSON, etc.)

Best Practices

  1. Use verified routes - Always use ~p sigil for compile-time safety
  2. Group related routes - Use scopes to organize routes logically
  3. Limit resource actions - Only generate routes you actually need
  4. Name scopes clearly - Use descriptive scope prefixes and aliases
  5. Keep pipelines focused - Each pipeline should have a single responsibility
  6. Order routes carefully - More specific routes should come before general ones
  7. Use resources - Prefer resources over individual route declarations
  8. Document custom routes - Add comments for non-standard routing patterns
  9. Avoid deep nesting - Limit nested resources to 2-3 levels maximum
  10. Version APIs - Use scopes for API versioning
  11. Secure sensitive routes - Apply authentication pipelines appropriately
  12. Test route resolution - Verify routes resolve to correct controllers
  13. Use forward wisely - Forward to well-defined plug interfaces
  14. Inspect regularly - Use mix phx.routes during development
  15. Follow conventions - Stick to RESTful conventions for resources

Common Pitfalls

  1. Hardcoding paths - Using strings instead of verified routes
  2. Over-nesting resources - Creating deeply nested resource hierarchies
  3. Missing pipeline - Forgetting to pipe routes through required pipelines
  4. Wrong route order - General routes catching specific route requests
  5. Exposing all actions - Generating unnecessary CRUD routes
  6. Not using scopes - Repeating controller module prefixes
  7. Inconsistent naming - Mixing naming conventions for routes
  8. Skipping CSRF protection - Removing security plugs without understanding implications
  9. Missing authentication - Not protecting sensitive routes
  10. Duplicate routes - Defining the same route in multiple places
  11. Incorrect HTTP verbs - Using wrong verbs for actions (GET for destructive actions)
  12. Not testing routes - Failing to verify route configuration
  13. Exposing internal routes - Making debug/admin routes available in production
  14. Complex route logic - Putting business logic in route definitions
  15. Ignoring route conflicts - Not checking for overlapping route patterns

Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

OpenCode

27.52%
按下载量换算45

Codex

23.51%
按下载量换算38

Claude Code

18.85%
按下载量换算31

Antigravity

11.21%
按下载量换算18

windsurf

7.75%
按下载量换算13

trae

3.63%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills