Fork me on GitHub
#reitit
<
2022-08-24
>
Chase22:08:47

I have a small reagent app that I run/build through shadow-cljs. I am trying to add some small routing functionality with reitit-frontend. The routing works correctly when running my dev build but then breaks in the production release. I get a 404 whenever I go to any route outside of the root one. Any clue why that might be happening?

Chase22:08:19

Here is the repo, with almost all the functionality happening in core.cljs : https://github.com/Chase-Lambert/homepage/blob/main/src/homepage/core.cljs which I mostly adapted from the reitit frontend easy example.

Chase22:08:26

If this is a #shadow-cljs thing I can move it over there.

Chase22:08:16

I also noticed the routing doesn't work in the dev build when I had {:use-fragment true} either.

rolt10:08:51

if you don't use fragment it's a real URL routing that's happening so i'm not surprised it fails. The real question is, why doesn't use-fragment work in dev ?

Chase14:08:40

Hmmm. But setting use-fragment to true doesn't work in production either.

Chase14:08:26

Basically the website is for my programming related stuff where I'm practicing learning Reagent and such so I want it to be a SPA, but I want to be able to send some people (my English students) to a specific part of the website (`/teaching`) that's separate from the other stuff on the site. Is reitit-frontend maybe not a good way to accomplish that?

Chase15:08:24

Wait a second. So I actually ran the reitit frontend example to hopefully better understand how it works and noticed the url includes a # in between the root url and the route. Putting that same # in my url obviously works too. So it's been working this whole time. Oof. hahaha. Oh man. I'm probably really showing my web dev naivete here. I obviously didn't quite understand what the docs were telling me when researching what that whole use-fragment thing was signifying.

Chase15:08:43

Would someone mind giving a quick breakdown on why we put that # in there?

Chase15:08:34

it seems to be that the # is what signifies that the route is a URL fragment. I assume that is how you do routing alongside a SPA. So I will gear my search towards that. Anyways, thanks for allowing me to rubber duck develop with you folks. hahaha

rolt15:08:21

yup, the # is a trick to implement "routing" in a SPA, that way you stay on the same page but you still have the advantages of regular routing (URL that point to the routed page, history, etc)