-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default route #388
Labels
Comments
Something like this. Not sure yet how efficient this is. class IndexFile(File):
def __init__(self):
super().__init__(os.path.join(static_files_at, 'index.html'))
self.isLeaf = True
def getChildWithDefault(self, path, request):
return self
def __repr__(self):
return 'IndexFile()'
index_file = IndexFile()
class RewritingResource(File):
def getChildWithDefault(self, path, request):
child_resource = super(RewritingResource, self).getChildWithDefault(path, request)
if isinstance(child_resource, NoResource):
# Rewrite to /
return index_file
return child_resource
def __repr__(self):
return 'RewritingResource()' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there an option to set up a "default" route?
Right now, a lot of frontend applications use HTML5 history mode for in-app navigation. This results in URL being replaced in browser history (ex.
/ => hello
) without actually making a request to the new URL. This allows for frontend applications to replace their content dynamically, and use frontend only routing.The issue is, if user reloads the page or just visits the URL by hand, there seems no way to handle that in Klein - at least I found nothing like that in source or docs - correct me if I am wrong here. As a result, user gets 404d.
If there is no such option, could we add one? If so, it should be possible to:
Kind of like
REQUEST /hello/world => 404? => rewrite path to / => REQUEST /
Less having hardcoded paths, not sure if there is a better way.
The text was updated successfully, but these errors were encountered: