Skip to content
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

Improve the base_path story #2381

Merged
merged 4 commits into from
May 3, 2024
Merged

Improve the base_path story #2381

merged 4 commits into from
May 3, 2024

Conversation

pyrrho
Copy link
Contributor

@pyrrho pyrrho commented May 2, 2024

This PR updates how the the axum router constructed for dx serve, the --open option, and the dioxus-router WebHistory interact with the Dioxus.toml base_path field.

Prior to this change, running dx serve with a base_path set always resulted in my browser displaying the "Outside of the base path: blah" message, even when I was navigating to routes that were very definitely inside of the base path.

Three major changes are included in this PR;

  • Setting a base_path now causes the dx serve router to be nested under the base path, rather than treating the base path as a route that is handled with a axum::routing::any_service.
  • The --open flag now opens to localhost:8080/<base_path> rather than to localhost:8080.
  • The dioxus router's default web history initializes to a URL that includes the base_path, rather than to the root.
    This last change is actually what I consider to be the most important, as it impacts dioxus web applications hosted outside of the dx serve axum server. Without this change, navigating to e.g. localhost:8080/base/path/ would cause the browser address bar to resolve to localhost:8080, even though following a Link { to: Route::Home {}, .. } would push localhost:8080/base/path/ onto the history stack.

Copy link
Member

@ealmloff ealmloff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works much better. Thank you!

@ealmloff ealmloff merged commit 010dcf9 into DioxusLabs:main May 3, 2024
8 of 9 checks passed
@pyrrho
Copy link
Contributor Author

pyrrho commented May 4, 2024

Thank you for finalizing this PR, and buttoning up the big ugly comment!

pyrrho added a commit to pyrrho/dioxus that referenced this pull request May 4, 2024
* Improve the base_path story

* allow base path routes without trailing slash

* remove note about trailing /

* fix clippy empty docs

---------

Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants