reflex icon indicating copy to clipboard operation
reflex copied to clipboard

custom-route can't be found.

Open Shulelk opened this issue 3 years ago β€’ 15 comments

  • Python Version: 3.9
  • Pynecone Version: latest
  • OS: windows 10
  • Browser (Optional): edge

About page and Index page is ok, but when I try to custom-route give me this message: Invariant: attempted to hard navigate to the same URL /custom-route http://localhost:3000/custom-route


This is my main code:

def about(): return pc.text("About page")

def custom(): return pc.text("custom")

app = pc.App(state=State) app.add_page(index) app.add_page(about) app.add_page(custom, path="/custom-route") app.compile()


I don't kown why, this is just a example in docs.

Shulelk avatar Jan 24 '23 05:01 Shulelk

Ok that's odd I just tried an example using that path and it seemed to work for me. Anyone else getting this issue?

Alek99 avatar Jan 24 '23 05:01 Alek99

\lib\site-packages\pynecone\compiler\utils.py line 305, in write_page with open(path, "w") as f: PermissionError: [Errno 13] Permission denied: '/custom-route.js'

Shulelk avatar Jan 24 '23 05:01 Shulelk

Can you post your whole python file, thanks.

Alek99 avatar Jan 24 '23 05:01 Alek99

"""Welcome to Pynecone! This file outlines the steps to create a basic app."""
from pcconfig import config

import pynecone as pc

docs_url = "https://pynecone.io/docs/getting-started/introduction"
filename = f"{config.app_name}/{config.app_name}.py"


class State(pc.State):
    """The app state."""

    pass


def index():
    return pc.center(
        pc.vstack(
            pc.heading("Welcome to Pynecone!", font_size="2em"),
            pc.box("Get started by editing ", pc.code(filename, font_size="1em")),
            pc.link(
                "Check out our docs!",
                href=docs_url,
                border="0.1em solid",
                padding="0.5em",
                border_radius="0.5em",
                _hover={
                    "color": "rgb(107,99,246)",
                },
            ),
            spacing="1.5em",
            font_size="2em",
        ),
        padding_top="10%",
    )

def about():
    return pc.text("About page")

def custom():
    return pc.text("custom")

def test():
    return pc.text("ok")



app = pc.App(state=State)
app.add_page(index)
app.add_page(about)
app.add_page(test)
app.add_page(custom,path="/custom-route")
app.compile()

Shulelk avatar Jan 24 '23 05:01 Shulelk

I tried this and it worked fine for me.

"""Welcome to Pynecone! This file create a counter app."""
import pynecone as pc

class State(pc.State):
    pass

def index():
    return pc.text("Example")

def about():
    return pc.text("About page")

def custom():
    return pc.text("custom")

app = pc.App(state=State)
app.add_page(index)
app.add_page(about)
app.add_page(custom, path="/custom-route")
app.compile()

Alek99 avatar Jan 24 '23 05:01 Alek99

Your file worked for me as-well, that's odd. Maybe a windows error I'm on Mac if any other users get this error I'll take a deeper look

Alek99 avatar Jan 24 '23 05:01 Alek99

Just an idea but maybe Windows doesn't like that the file created start with a /

Try

app.add_page(custom, path="custom-route")

Instead

Lendemor avatar Jan 24 '23 06:01 Lendemor

Thanks, good suggestion @Lendemor this seems to work as seen on discord. We will fix this so the "/" way works aswell in the next release

Alek99 avatar Jan 24 '23 07:01 Alek99

Thanks, good suggestion @Lendemor this seems to work as seen on discord. We will fix this so the "/" way works aswell in the next release

Okay, I'll wait the time the problem is resolved.

Shulelk avatar Jan 24 '23 10:01 Shulelk

\lib\site-packages\pynecone\compiler\utils.py line 305, in write_page with open(path, "w") as f: PermissionError: [Errno 13] Permission denied: '/custom-route.js'

I've the same issue in Windows, because the script tries to write to the home path C:\ where admin privileges are required, as a temporary workaround run the script as admin.

HellAmbro avatar Jan 25 '23 14:01 HellAmbro

I've the same issue in Windows, because the script tries to write to the home path C:\ where admin privileges are required, as a temporary workaround run the script as admin.

I have tried running as administrator but it didn't work for me.

Shulelk avatar Jan 26 '23 08:01 Shulelk

Ok got it thanks for pointing this out we are on Mac so these bugs can be hard to find. We can look into a fix, if any of you know an easy fix on windows lmk

Alek99 avatar Jan 26 '23 08:01 Alek99

I don't want to be wrong but I think it is due to how the file system handles paths, on Linux & Mac it should work, while on Windows it doesn't. Maybe some form of escaping is needed. I will try to take a look at it as soon as possible and try to solve it.

HellAmbro avatar Jan 26 '23 12:01 HellAmbro

  • Python Version: 3.9
  • Pynecone Version: latest
  • OS: windows 10
  • Browser (Optional): edge

About page and Index page is ok, but when I try to custom-route give me this message: Invariant: attempted to hard navigate to the same URL /custom-route http://localhost:3000/custom-route

This is my main code:

def about(): return pc.text("About page")

def custom(): return pc.text("custom")

app = pc.App(state=State) app.add_page(index) app.add_page(about) app.add_page(custom, path="/custom-route") app.compile()

I don't kown why, this is just a example in docs.

Figured it out: When using Pynecone on Windows, it's using NPM and JavaScript so you have to specify the path as "./custom-route" rather than the python version: "/custom-route"

xtinktstudios avatar Jan 27 '23 07:01 xtinktstudios

Awesome we will automatically format the path correctly as a fix

picklelo avatar Jan 27 '23 07:01 picklelo