Skip to content

Route Aliases #5418

@populated

Description

@populated

I think it would be cool if there were built-in aliases for routes, for example:

@route(
    "/information",
    aliases=["/info", "/faq"] # <- They all show the same thing as the main route `/information`.
)

It might be useless to some, but I don't. I think it would be useful to allow people to define multiple aliases for one route. It is possible as of now using this code I made:

from typing import List, Callable, Union
from flask import Flask, wraps, redirect, jsonify

app = Flask(__name__)

def route(name: str, aliases: List[str] = [], **options) -> Callable:
    def decorator(func: Callable) -> Callable:
        @app.route(name, **options)
        @wraps(func)
        async def wrapper(*args, **kwargs) -> Union[redirect, jsonify]:
            return await func(*args, **kwargs)

        [app.route(alias, **options)(wrapper) for alias in aliases]

        return wrapper

    return decorator

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions