Files
SnowLuma/.pnpm-store/v11/files/0d/b04f7568beb7aada9529f80f8f9b54c503768b4da02a9b660f160627c8de34c558ab47ab3965881d0665186edc2f5510b01ac574bfce4056cdc333229a1224
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

77 lines
2.4 KiB
Plaintext

import { RouterRoute } from "../../types.js";
import { Context } from "../../context.js";
//#region src/helper/route/index.d.ts
/**
* Get matched routes in the handler
*
* @param {Context} c - The context object
* @returns An array of matched routes
*
* @example
* ```ts
* import { matchedRoutes } from 'hono/route'
*
* app.use('*', async function logger(c, next) {
* await next()
* matchedRoutes(c).forEach(({ handler, method, path }, i) => {
* const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
* console.log(
* method,
* ' ',
* path,
* ' '.repeat(Math.max(10 - path.length, 0)),
* name,
* i === c.req.routeIndex ? '<- respond from here' : ''
* )
* })
* })
* ```
*/
export declare const matchedRoutes: (c: Context) => RouterRoute[];
/**
* Get the route path registered within the handler
*
* @param {Context} c - The context object
* @param {number} index - The index of the route from which to retrieve the path, similar to Array.prototype.at(), where a negative number is the index counted from the end of the matching route. Defaults to the current route index.
* @returns The route path registered within the handler
*
* @example
* ```ts
* import { routePath } from 'hono/route'
*
* app.use('*', (c, next) => {
* console.log(routePath(c)) // '*'
* console.log(routePath(c, -1)) // '/posts/:id'
* return next()
* })
*
* app.get('/posts/:id', (c) => {
* return c.text(routePath(c)) // '/posts/:id'
* })
* ```
*/
export declare const routePath: (c: Context, index?: number) => string;
/**
* Get the basePath of the as-is route specified by routing.
*
* @param {Context} c - The context object
* @param {number} index - The index of the route from which to retrieve the path, similar to Array.prototype.at(), where a negative number is the index counted from the end of the matching route. Defaults to the current route index.
* @returns The basePath of the as-is route specified by routing.
*
* @example
* ```ts
* import { baseRoutePath } from 'hono/route'
*
* const app = new Hono()
*
* const subApp = new Hono()
* subApp.get('/posts/:id', (c) => {
* return c.text(baseRoutePath(c)) // '/:sub'
* })
*
* app.route('/:sub', subApp)
* ```
*/
export declare const baseRoutePath: (c: Context, index?: number) => string;
export declare const basePath: (c: Context, index?: number) => string;
//#endregion