reflex icon indicating copy to clipboard operation
reflex copied to clipboard

pc.redirect not work

Open evandeng2009 opened this issue 2 years ago β€’ 3 comments

Describe the bug A component defiend as following and given to app.add_custom_404_page(page_not_found):

def page_not_found() -> pc.Component: return pc.redirect("/")

get such an error: page.children.append( ^^^^^^^^^^^^^ AttributeError: 'EventSpec' object has no attribute 'children'

To Reproduce Steps to reproduce the behavior:

  • Code/Link to Repo:

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

** Specifics (please complete the following information):**

  • Python Version:
  • Pynecone Version:
  • OS:
  • Browser (Optional):

Additional context Add any other context about the problem here.

evandeng2009 avatar Jun 01 '23 16:06 evandeng2009

pc.redirect is an event (as denoted by the EventSpec type that is returned by your page_not_found() method.

It's normal your code does not work.

What you want to do is to use an empty page with an on_load method that does the redirect:

app.custom_404_page(pc.fragment(), on_load=pc.redirect("/"))

Lendemor avatar Jun 01 '23 16:06 Lendemor

@Lendemor I don't see an on_load method of app.custom_404_page.

def add_custom_404_page(
        self,
        component,
        title=None,
        image=None,
        description=None,
        meta=constants.DEFAULT_META_LIST,
    ):

evandeng2009 avatar Jun 04 '23 15:06 evandeng2009

I literally don't know anything about pynecone except it's a pure python solution for web pages but note that is custom_404_page not add_custom_404_page, you can check it with this two ways:

...
import inspect
print(inspect.getsource(app.custom_404_page))

It will show the source code of the function, also you can do this:

...
import code
code.interact(local=locals())
>>> help(app.custom_404_page)

It opens an interactive session and call help() with the function.

nacho00112 avatar Jun 18 '23 19:06 nacho00112