Git Product home page Git Product logo

Comments (18)

rmorshea avatar rmorshea commented on June 10, 2024 1

I've created a draft implementation here: https://github.com/idom-team/idom-router

I would discourage using it until I've had the time to flesh it out with more tests and documentation. The interface is subject to change (I haven't looked too closely at how React Router does things yet). I'm mostly interested in getting some early feedback on the implementation or for interface suggestions. For the moment though, usage looks like:

from idom import component, html, run
from idom.backend import default

from idom_router.router import Route, Link, bind

Router = bind(default)

@component
def Sample():
    return Router(
        Route("/", Link({"id": "root"}, "to a", to="/a")),
        Route("/a", Link({"id": "a"}, "to b", to="/b")),
        Route("/b", Link({"id": "b"}, "to c", to="/c")),
        Route("/c", Link({"id": "c"}, "to default", to="/default")),
        Route("/*", html.h1({"id": "default"}, "Default")),
    )

run(Sample)

Route patterns follow standard glob rules (see fnmatch module for details) unless an re.Pattern is provided.

Also, inside your routes, if you want to get the current location, you need to use use_location from idom_router. The use_location hook from the backend implementation will always give you the location the user initially arrived at.

from reactpy-router.

Archmonger avatar Archmonger commented on June 10, 2024

Examples have been added on potential styling patterns.

There's a very high chance we pick the react style, but just want to make sure options are listed.

from reactpy-router.

Archmonger avatar Archmonger commented on June 10, 2024

I've updated this with a deep dive into what React-Router API endpoints need to be replicated for MVP URL routing support.

from reactpy-router.

rmorshea avatar rmorshea commented on June 10, 2024

I've done a little bit of thinking on this here and there and at the moment I'm leaning towards the idea of making this a separate package (e.g. idom-router). I'm also imagining that the implementation might rely on Web Components.

from reactpy-router.

Archmonger avatar Archmonger commented on June 10, 2024

If it can be a separate package then it should be.

But need to consider whether the current infrastructure is flexible enough to support URL routing outside of core.

from reactpy-router.

rmorshea avatar rmorshea commented on June 10, 2024

Agreed. Especially given this is how react does it. With that said, without charges to core I'm not sure how clean the implementation will be. Regardless, I'm thinking I hack a prototype and see how bad it is before I go making changes in core before I really groc how routing works.

from reactpy-router.

Archmonger avatar Archmonger commented on June 10, 2024

I'm not entirely sure what you're trying to do with the third and fourth positional arguments ("to a", to="/a") in Route, but everything else about the overall design for Router and Route seems solid.

I would rename Router to BrowserRouter to be consistent with react-router.

from reactpy-router.

Archmonger avatar Archmonger commented on June 10, 2024

This issue should be transferred to idom-team/idom-router

from reactpy-router.

Archmonger avatar Archmonger commented on June 10, 2024

Is this issue closable, since the initial package has been released?

Or are we keeping it open to track the development goals?

from reactpy-router.

rmorshea avatar rmorshea commented on June 10, 2024

I think we can close this. Any features mentioned here that we should still implement can be created as separate issues.

from reactpy-router.

Archmonger avatar Archmonger commented on June 10, 2024

Should we have a quick discussion on which of the "Things to be implemented" on this issue are worth moving forward with?

from reactpy-router.

bobwatcherx avatar bobwatcherx commented on June 10, 2024

is there a complete example to do routing with reactpy_router and with navigation links

i get errror

root@miop-HP-Convertible-x360-11-ab1XX:/home/miop/belajar/reactpy-router# python3 main.py 
Traceback (most recent call last):
  File "/home/miop/belajar/reactpy-router/main.py", line 2, in <module>
    import reactpy_router
  File "/home/miop/belajar/reactpy-router/reactpy_router/__init__.py", line 4, in <module>
    from . import simple
  File "/home/miop/belajar/reactpy-router/reactpy_router/simple.py", line 9, in <module>
    from reactpy_router.core import create_router
  File "/home/miop/belajar/reactpy-router/reactpy_router/core.py", line 117, in <module>
    module_from_file("reactpy-router", file=Path(__file__).parent / "bundle.js"),
  File "/usr/local/lib/python3.10/dist-packages/reactpy/web/module.py", line 196, in module_from_file
    raise FileNotFoundError(f"Source file does not exist: {source_file}")

from reactpy import component, html, run

from reactpy_router import Route, Link, bind



@component
def App():
    return html.h1("Hello, world!")


run(App)

from reactpy-router.

rmorshea avatar rmorshea commented on June 10, 2024

Are you running this using a developer installation? I don't get this error if I just pip install reactpy-router.

from reactpy-router.

bobwatcherx avatar bobwatcherx commented on June 10, 2024

i have installed with pip install reactpy-router . but when running it still error like that

info

root@miop-HP-Convertible-x360-11-ab1XX:/home/miop/belajar/reactpy-router# python3 --version
Python 3.10.6

from reactpy-router.

bobwatcherx avatar bobwatcherx commented on June 10, 2024

now I have resolved the error by reinstalling the package . is there a way to use it up to router parameters, router queries, and more details

root@miop-HP-Convertible-x360-11-ab1XX:/home/miop/belajar/reactrouter-py# python3 main.py
Traceback (most recent call last):
File "/home/miop/belajar/reactrouter-py/main.py", line 3, in
from reactpy_router import Route, Link, bind
ImportError: cannot import name 'Link' from 'reactpy_router' (/usr/local/lib/python3.10/dist-packages/reactpy_router/init.py)

from reactpy-router.

rmorshea avatar rmorshea commented on June 10, 2024

There's some WIP docs here.

from reactpy-router.

bobwatcherx avatar bobwatcherx commented on June 10, 2024

can the link be inserted into the button like this

html.button({
"to":"/about"
},"To about")

but not working or there is another way

from reactpy-router.

rmorshea avatar rmorshea commented on June 10, 2024

Please start a discussion: https://github.com/reactive-python/reactpy-router/discussions

from reactpy-router.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.