oedotme / generouted

Generated file-based routes for Vite
https://stackblitz.com/github.com/oedotme/generouted/tree/main/explorer
MIT License
1.02k stars 47 forks source link

Question: usage without TypeScript #156

Closed Khalilsqu closed 5 months ago

Khalilsqu commented 6 months ago

Describe the Bug

Can this be used without typescript?

I am trying it without typescript now!! I observe that it does not reload after code changes. there are also many strange behavoirs!!

Generouted Version

latest

Your Example Website or App or Reproduction

just want to ask a question

Steps to Reproduce the Bug or Issue

normal use

Expected Behavior

normal use

Screenshots or Videos

No response

Platform

windows

Additional context

No response

ferretwithaberet commented 6 months ago

Seems like you can, thought it's quite ugly. You can remove the vite plugin and use:

import { components, hooks, utils } from "@generouted/react-router/client";

export const { Link, Navigate } = components();
export const { useModals, useNavigate, useParams } = hooks();
export const { redirect } = utils();

as your router.js file.

DISCLAIMER:

I do not know if using this package without typescript breaks anything else, I just noticed that if you do it like this, it still works.

Khalilsqu commented 6 months ago

thanks, Just tested and yes it works without TS.

oedotme commented 5 months ago

@Khalilsqu You can use generouted without TypeScript with no issues, the optional generated router.ts file contains only types for the type-safety that you can actually benefit from while you're using just JavaScript. You could disable generating this file by simply not using the Vite plugin as @ferretwithaberet suggested but I wouldn't recommend that.

On the run-time level, both .tsx and .jsx files are supported for routes declaration. You can declare all your routes with the jsx extension instead of tsx as most of the example on this repo.

Hope that helps, and in case you're having an issue with the usage — you could open an issue with the problems you've faced or re-open this one.