S
Solara5mo ago
Harry

404 Solara Router

Hi, when you try and go to a Solara page which doesn’t exist you will see a very simple page which has the text "Page not found by Solara router". Is there a way of either replacing this with a different page, eg my own 404 page not found, or redirecting the user from the default Solara "Page not found by Solara router" page to one I define, eg my own 404 page not found?
6 Replies
iisakkirotko
iisakkirotko5mo ago
Hey @Harry! Currently it's not possible to customize the 404 page, or to redirect to a different page. This would be a good feature to have, so I'll take another look at implementing this next week, unless you would like to work on it and open a PR. Let me know if you do and maybe I can give you some pointers
Harry
Harry5mo ago
Hi @cr33pyguy, thannk you for getting back. Unfortunately, I don't have time to work on this at the moment, but it would be an awesome and very useful feature for Solara!
iisakkirotko
iisakkirotko5mo ago
No worries! I'll try and take a look at it later this week.
Harry
Harry5mo ago
awesome thank you @cr33pyguy
MaartenBreddels
MaartenBreddels5mo ago
@Harry please take a look at https://github.com/widgetti/solara/pull/670
Monty Python
Monty Python5mo ago
maartenbreddels
<:pull_open:882464248721182842> [widgetti/solara] fix: if we hit a 404 in starlette, raise instead of render a 404
This allows middleware or error handlers to catch the 404 and do something custom. Example:
import solara

clicks = solara.reactive(0)

added = False

def add_exception_handler():
global added
print("add_exception_handler", added)
if not added:
import solara.server.starlette
from starlette.responses import HTMLResponse
async def server_error(request, exc):
return HTMLResponse(content="My custom 404", status_code=exc.status_code)

solara.server.starlette.app.add_exception_handler(404, server_error)
added = True

@solara.component
def Page():

add_exception_handler()
solara.Text("hello world")
import solara

clicks = solara.reactive(0)

added = False

def add_exception_handler():
global added
print("add_exception_handler", added)
if not added:
import solara.server.starlette
from starlette.responses import HTMLResponse
async def server_error(request, exc):
return HTMLResponse(content="My custom 404", status_code=exc.status_code)

solara.server.starlette.app.add_exception_handler(404, server_error)
added = True

@solara.component
def Page():

add_exception_handler()
solara.Text("hello world")
Created
Want results from more Discord servers?
Add your server