-
Notifications
You must be signed in to change notification settings - Fork 85
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
Facing some issues changing "hash" routing to "path" routing #30
Comments
Hi For the server However So what you need is a server that gives you the same page regardless of the path. So if you hit The key of all this is the server implementation. In the example you can see this here: The elm-tutorial-app uses webpack dev server. Have a look at https://webpack.js.org/configuration/dev-server/#devserver-historyapifallback , however you will need to learn a bit of webpack to do this. |
Thanks @sporto for the elaborate explanation. As a matter of fact after few hours of posting this issue I searched elm lang navigation 404 on Google and I found this Stackoverflow Post which you have answered and it mentions the same solution i.e using webpack's While I do that I am adding below my understanding, after your explanation above, regarding how the pieces fit together and I would request you to provide your confirmation on the same: When we first time input Main.elm
matches the route Models.elm
After setting the initial route, it triggers command Commands.elm
Once the data is fetched it triggers a msg Update.elm
Then the view is rendered which matches the View.elm
Now that the top route is handled everything now stays in Elm-court. The navigation button or links when clicked requests data from remote server (the API server serving at port 4000). So Similarly when And that perfectly makes sense because Client server (serving on port 3000) doesn't have any routes configured to served from itself. Each route configured is aimed to be served from API server (serving on port 4000) Now a question arises that if Client server is not configured to serve any route then how come it is able to serve the We are using webpack-dev-server and as per its documentation
And we do have an index.html in our src folder configured to be rendered like this: in webpack.config.js
in index.js
@sporto can you please confirm this understanding of mine of the flow? If I am wrong at any place requesting you to rectify me. Thanks. |
@sporto One more confusion I have is regarding loading data for Edit route When we click on Edit btn and the flow reaches to View.elm, in View.elm
So does this function Update.elm
I strongly feel that that should be the case. But can you please confirm this understanding of mine? If I am correct then consider the scenario where in players list doesn't contain some specific information related to a Player which is not available in the list, say Player's Profile information. This profile information should usually be available in the player's details end-point exposed by API
Obviously then the following logic cannot help in rendering the profile information because it as of now just filters data from pre-obtained players list and to achieve the desired purpose we should explicitly request data from end-point
Thanks. |
@sporto First of all Thanks a lot for this awesome tutorial. From start-to-end I didn't faced any discrepancy or errors executing the code given in tutorial on my dev machine.
Now coming to the issue I am facing:
In section Navigation approaches here you have mentioned the cons of using hash routing and as an alternative suggesting to use path routing which does look intuitive compared to the hash routing. I followed the example you referred to in https://github.com/sporto/elm-navigation-pushstate and updated my code such that it uses path routing.
The changes I made can be found below:
Msgs.elm
Routing.elm
CustomHtmlEvents.elm (newly introduced)
Players/List.elm
Players/Edit.elm
And that does work! Please refer the screenshots attached while navigating:
1.png (top route)
2.png (Player route)
3.png (Players route accessed via clicking the List link on top-left in 2.png)
Now what I am unable to understand is that when I try to access routes clicking navigation links they work. However when I manually change the route in browser's address bar like
http://localhost:3000/players
I get followinghttp://localhost:3000/players/2
I get followinghttp://localhost:3000/
- This one does work by showing the Listing.http://localhost:3000/#players
- This one too works by showing the Listing but I am wondering why? Why this "hash" routing works?However
http://localhost:3000/#players/2
doesn't work.So I am seeking your help in understanding the above behavior regarding manually changing the URL in address bar and they returning 404 response and how to fix them up to behave as expected i.e. whether I type in the URL or use navigation button or links they should show the desired data.
I have just started learning Elm and also novice to Functional Programming so please bear me on any questions I asked which sound silly to you.
Again Thank you so much for this wonderful tutorial. It demonstrates sheer clarity you have with this tutorial and is definitely one of the foremost resources one should refer to get started with Web App Development with Elm and at the same time getting acquainted the language's core concepts.
The text was updated successfully, but these errors were encountered: