I have 3 routes rendered in a browser router. the ...
# javascript
c
I have 3 routes rendered in a browser router. the home is correctly rendered but localhost:8080/login and localhost:8080/dashboard both render Cannot GET /login ( or /dashboard )
Copy code
val appRouter = createBrowserRouter(
    arrayOf(
        jso {
            path = "/"
            element = Home.create()
        },
        jso {
            path = "login"
            element = Login.create()

        },
        jso {
            path = "dashboard"
            element = Dashboard.create()
        }
    )
)
Any hint here?
a
You should put
login
and
dashboard
into the
children
section of the
/
path like this: https://reactrouter.com/en/main/routers/create-browser-router
Copy code
val appRouter = createBrowserRouter(
    arrayOf(
        jso {
            path = "/"
            element = Home.create(),
            children = arrayOf(
                jso {
                    path = "login"
                    element = Login.create()
                },
                jso {
                    path = "dashboard"
                    element = Dashboard.create()
                }
            )
        },
    )
)
c
I still have Cannot GET /login when I enter http://localhost:8080/login in the browser. The kotlin wrapper bom version in use is 1.0.0-pre.623
a
@turansky ^^
t
If you do it without server (like Ktor) - you have only 1 available page (
index.html
usually). For other pages you need redirect from server. If you don't want to use server - you can use createHashRouter (example).
FYI - In latest wrappers you can use
Component
property
Copy code
val appRouter = createBrowserRouter(
    arrayOf(
        jso {
            path = "/"
            Component = Home,
            children = arrayOf(
                jso {
                    path = "login"
                    Component = Login
                },
                jso {
                    path = "dashboard"
                    Component = Dashboard
                }
            )
        },
    )
)
c
Thanks for the hint @turansky, we were using hash router but were not fond of it. is there any example using ktor to achieve a complete routing using browserRouter? if not, I'd just like to understand how ktor helps there and how it solves the issue. Thanks in advance
t
Ktor returns default page for all "page-like" requests. On client side router decide what to show at start. In your case only client knows about
login
and
dashboard
pages. For other pages you can register page
404
in router.
c
Thanks, @turansky. Cc @DGensert