-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
preact-router not compatible with history v5 types #423
Comments
Well, types not lining up doesn't mean it's incompatible necessarily. Ideally they would, but TS type incompatibilities are pretty common in the ecosystem as a whole. Now, if you get runtime errors then absolutely. You might need to configure your
This is purely a result of your strict configuration; you can disable It does have types at
The error tells you exactly what the problem is: This is the same issue as #414, and maybe there's a disconnect here? Hash routers only work in a browser environment, therefore you cannot use them in Node, which You can get around this by dropping out of prerendering or using window checks (see https://github.com/preactjs/preact-cli#pre-rendering). However, without the router being available, there's likely little value in prerendering. |
You're right, this kind of type error sometimes occurs in the TypeScript ecosystem. However, it has been two years since the last release of the |
This comment was marked as off-topic.
This comment was marked as off-topic.
@rschristian |
Indeed, so perhaps that comment was not super relevant, though I would urge people to really consider whether they need hash routing. By and large, they're a relic with very few uses today. |
The use case I had in mind when I originally opened the ticket was deploying a preact page on a static host such as Github Pages or AWS S3. On there you'd deploy a single And on these deployments it makes a difference if the route is
because in the first case if a user goes to that route, the static page server will respond with an error page and/or error response code even before the preact code has any chance to run. In the second case the user goes to On some deployments there are workaround but on others there are not; and there's also a high chance that I might not fully understand how such a preact deployment without a hash router is supposed to look like. Just adding this context because from this use case's point of view a hash router is definitely needed. Is this not a use case other people are running into and am I just using this wrong? |
I'll also throw in hash routing is useful for local/standalone deployment scenarios as well. Having the ability to do both means you routing can "just work" regardless of whether you control the server, or if it is even on a server. While these are not the most common use case, they are not uncommon either. |
Ideally those static hosts that are still stuck in the 90's will catch up though -- Nginx & Apache have offered fallback routes for 20+ years, there's no valid technical reason why some hosts are unable to do the same. |
That is of course your prerogative. I only wanted to voice support for the feature as it is something I'd use myself. |
Was this not fixed in #410 ? It's still an issue for me |
The implementation was fixed so that it functions as intended; types are a separate issue however, and one that won't be addressed as |
@rschristian is there a viable alternative to |
If you need hash routing, you can look to With |
Hey folks,
I'm on [email protected] and [email protected] (both latest stable versions), and I'm running into similar / the same issues as reported in #385. I was looking around a bit and found #410 and #387 which claim to have solved the history v5 issue.
I have checked my package and package-lockfile to make sure the versions installed are the versions reported above.
Here is the use case and the error message, in case it helps
Workarounds I tried (and don't work)
Downgrading to history@4 does not work, because it doesn't seem to come with typescript types, and tsc type checking then fails.
Using history@5 with the workaround from Typescript hash router error #385 (comment) type-checks, but then at build time results in a very strange non-descriptive error message.
Any ideas what could be the cause of this? Curious if other folks successfully are using latest preact-router and history v5 with typyescript. Let me know if I can provide more information here.
The text was updated successfully, but these errors were encountered: