pallets / werkzeug

The comprehensive WSGI web application library.
https://werkzeug.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
6.66k stars 1.73k forks source link

[Change request] "Angular Component Router" support #1016

Closed rognoni closed 8 years ago

rognoni commented 8 years ago

For my project I have to use Angular2 routing, for example http://127.0.0.1:5000/detail/11 but I see this error:

Not Found

The requested URL was not found on the server.
If you entered the URL manually please check your spelling and try again.
import os.path
from flask import Flask
from werkzeug.wsgi import SharedDataMiddleware

app = Flask(__name__)

app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {
    '/': os.path.join(os.path.dirname(__file__), '.')
})

This is the lite-server description of this feature:

When creating a SPA there are routes that are only known to the browser. For example, /customer/21 may be a client side route for an Angular app. If this route is entered manually or linked to directly as the entry point of the Angular app (aka a deep link) the static server will receive the request, because Angular is not loaded yet. The server will not find a match for the route and thus return a 404. The desired behavior in this case is to return the index.html (or whatever starting page of the app we have defined).

untitaker commented 8 years ago

Backend frameworks are not supposed to support JS-framework specific behavior, and Werkzeug is not even that. You can do this yourself in application code very easily, but please ask on StackOverflow instead of here.