Skip to content

Base for routing #369

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

Closed
MartinKavik opened this issue Feb 24, 2020 · 2 comments
Closed

Base for routing #369

MartinKavik opened this issue Feb 24, 2020 · 2 comments
Labels
missing functionality Not quite a bug, but needs to be addressed

Comments

@MartinKavik
Copy link
Member

MartinKavik commented Feb 24, 2020

@jgrund Hi, I'm using a base tag in my seed app. When it's not / it seems to break routing. Is there a way to configure routing to work with a non / base?
In dev mode I want to have a / base, but in prod I want to have a /ui base
It would be nice if seed could account for what the base is and basically remove it from routing configs
Otherwise it seems that I need to conditionally account for what the base is dependant on the environment

Design decisions:

  1. Where we want to setup router base path? (In App builder, get from base tag from head, etc.)
  2. Should we change Url behaviour? I.e. base path would be trimmed from Url::path.
  3. How does it alter routing.rs functions behavior?
  4. How will be a tags handled?
  5. ..
@MartinKavik
Copy link
Member Author

Ad 1) We can set base url by creating a base element with href in head and then Seed gets base path by calling function baseUri.

  • Elm article about base url & routing.
  • How to get base path in JS - basePath = new URL(document.baseURI).pathname.
  • As the result, we can set base url directly in HTML, which should allows us to easily change it through ENV variables and bundlers.

Ad 2) Yes.
Ad 3) It looks like there shouldn't be any changes, but we should test it.
Ad 4) a link should be handled automatically thanks to base & href in head.

This was referenced Mar 8, 2020
@MartinKavik MartinKavik added this to the 2. Stable basic Seed API milestone Mar 9, 2020
@MartinKavik MartinKavik added the missing functionality Not quite a bug, but needs to be addressed label Mar 9, 2020
@MartinKavik
Copy link
Member Author

MartinKavik commented Apr 16, 2020

The big PR #411 that resolves many Url/project scaling-related issues, including this one, has been merged.
@jgrund Please reopen it once you have some problems with it (bugs, strange API, ..).

I recommend to play with new examples url and pages that both exercise the new functionality and app patterns - clone the repo and run e.g. cargo make start pages and then go to localhost:8000.

How it works:

  1. Seed tries to read <base href="ui"> during app start and extract a path from it. The extracted path is called base_path. If there is no base element or there were problems during casting, the default (empty / root) path is used.
  2. Seed passes Url into your init function or UrlChanged subscription message. However it modifies it a little bit before passing - it calls url.skip_base_path(base_path).
    skip_base_path advances internal path iterator if base_path is prefix of the url path - so url.next_path_part() returns a instead of ui if the base_path is ui and the url is /ui/a/xxx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing functionality Not quite a bug, but needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant