-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
No ability to change behavior depending on the current page #4
Comments
Hello @rovdyl, Thank you so much for leaving this feedback! I completely agree, this seems like a common sense feature to add that would be really useful in a lot of situations. Having an Great to get another perspective, thanks for chiming in! |
Excellent! elm-pages seems like a fantastic project and this was one of the only features preventing me from using it on a site of my own. Excited to see how this turns out |
Hello! So I did an initial change for this. Here's the PR: #8 I currently have I'm wondering which of these two approaches makes more sense for page changes though. If the user navigates to an invalid page:
The interesting thing is that your But it seems strange to have the user's The simplest thing to do might be to just always give the user that data (give them the most information possible) and pass What do you think of that idea? |
I think support for custom 404 pages would be a good idea, so adjusting In fact, if you really wanted to provide as much information as possible, instead of using a Whichever way you end up going, though, I think it would be best to call I'm not entirely sure which option of the three would be best, but with lack of a specific use case it may actually be best to go with the option that provides the simplest possible API. I suppose technically that would be the plain Hope these thoughts help in some way. |
I like the idea of passing the full URL instead of I wonder if it makes sense to treat 404 pages differently than a dynamic route? I guess the only reason it would be important would be if you want to actually have an HTTP status of 404, which may not actually be necessary for user-facing web applications (as opposed to machine-read API responses). I like the simplicity of having 404 pages just be another type of dynamic route, and then leaving it to the user to display a 404 message, OR display a dynamic route, based on their own routing logic. Or always display a 404 message for fallback (non-static) routes. I'll open a separate issue to discuss dynamic routing and 404s. This is definitely on the roadmap, but I'd like to tackle that issue separately and ship a simpler version of this for now. Changes for this iteration
That sounds like a good idea to have For this iteration, I'll start with this API: init : Maybe (PagePath pathKey) -> ( model, Cmd msg) onPageChange : Maybe (PagePath pathKey) -> msg Future iterationI'll revisit these ideas in the next round:
Here's a rough sketch of what that could look like. I think that there may need to be a different
type Route pathKey frontmatter = StaticRoute (PagePath pathKey frontmatter) | DynamicRoute Url
init : Route pathKey -> ( model, Cmd msg)
onPageChange : Route pathKey -> msg
staticView :
List ( PagePath pathKey, metadata )
->
{ path : PagePath pathKey
, frontmatter : metadata
}
->
StaticHttp.Request
{ view : Model -> View -> { title : String, body : Html Msg }
, head : List (Head.Tag Pages.PathKey)
}
dynamicView : List ( PagePath pathKey, metadata ) -> Url -> Model -> { title : String, body : Html msg } |
Thanks again for the really helpful input and brainstorming @rovdyl! I really appreciate the discussion! I'll be merging the changes I described in "Changes for this iteration" (unless you have any concerns about that design). This will go out with the major release that will include the |
Also, for reference, with Netlify you could set up redirects for custom 404s and dynamic routes using a rule like this:
Because of Netlify's route shadowing behavior, it will only do that redirect if it doesn't conflict with a static file that would satisfy a given route. So it would work perfectly for that use case! Full docs are here: https://docs.netlify.com/routing/redirects/rewrites-proxies/#history-pushstate-and-single-page-apps |
Thank you so much for hearing me out! This looks absolutely perfect to me, I really like the idea of having separate views like that. I think it's a lot cleaner than the idea I had in mind, and I'm excited to think about what |
Just adding my use-case here in case other folks are attempting something similar: a pop-up nav that should close when a link is clicked and the page is navigated to. I think the proposed |
Thanks for sharing your use case @tennety! That's good to know, especially because it gives a solid reason for triggering the msg even in cases where you navigate to a route that isn't found (even if the |
The initial version has been released! Let me know what you two think! 😄 |
The |
It is useful to trigger certain actions only upon loading a particular page/page type. My current thought would be to add an extra
onPageChange
field to the generatedPages.application
config, where you could supply an optional msg that would be called after a page has loaded, similar toonUrlChange
inBrowser.application
. Additionally, the init function would take an extra argument indicating the currently loaded page. Does this seem like a good/feasible idea, or am I misunderstanding something?The text was updated successfully, but these errors were encountered: