Replies: 3 comments
-
|
I created a gist for a workaround (not really elegant but it works so far). https://gist.github.com/Nightbr/c41a0390454ea36d0bd6caf96823396a |
Beta Was this translation helpful? Give feedback.
-
|
Hi! Instead of copying / embedding / updating a large part of this library codebase, I would simply recommend adding After that, declare a router file: import { createRouter } from "@swan-io/chicane";
// Search params constants
export const TOKEN_SEARCH_PARAMS = "token";
export const routes = {
AppArea: "/*",
AppRoot: "/",
// Auth
Login: "/login?:redirect",
ForgetPassword: "/forget-password",
ResetPassword: `/reset-password?:${TOKEN_SEARCH_PARAMS}`,
Register: "/register?:redirect",
RedeemInvite: `/redeem-invite?:${TOKEN_SEARCH_PARAMS}`,
} as const;
const { useRoute, push, replace, ...createLinkFns } = createRouter(routes);
export const Links = createLinkFns; // only export links creation functions |
Beta Was this translation helpful? Give feedback.
-
|
Hey, for sure this is a solution and the workaround is clearly nor ideal or elegant. We have different backend services some on k8s other on Lambda services, ... I need to investigate what impact this could have. IMO the best solution still is to have a core lib that is framework agnostic and binding libs. This could also enable the creation of bindings for other framework (Such as Svelte). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Why it is needed?
Hey,
first of all, thanks for this amazing Router that help us keeps our routes type safe 💪 We also love the simplicity in it's API and how it leverage existing solution such as ts-pattern.
For our use-case, we have a monorepo (manage by Nx) and we share some code (Domain) between frontend and backend. The list of app routes are shared and we would also be able to share the generated links functions that is build by the createRouter to be able to use it in backend.
Here is an example in our
user.service.tsWith this scaffolding, we have type safe links between our backend and frontend 🎉.
The only issue is that
createRouteris coupled withReactand create a dependency toReacton our backend.Possible implementation
A possible solution could be to publish a
createLinksfunction separately to be imported at it's own path without React dependency.We could also publish another package to npm such as
@swan-io/chicane-backendor something else.For now, as a workaround, we created a file
create-links.tsthat reuse your code in our domain lib without the React dependency (no push, no useRoute hook) but we have thecreateURLFunctionsthat generates all link functions.Also could be a good use of a monorepo with 2 libs:
core: contains all main functions and utils without React dependencyreact: contains the binding with React framework and the hook useRoutesPublish separately and
@swan-io/chicane-reactdepends on@swan-io/chicane-core.Happy to discuss possible solutions if you're interested in this feature :wink.
Code sample
Usage could be something like this.
Beta Was this translation helpful? Give feedback.
All reactions