yewstack / yew

Rust / Wasm framework for creating reliable and efficient web applications

Home Page:https://yew.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Yew router path matching cannot be triggered

sammyne opened this issue · comments

Problem

If there is already some static html occupying a path, access using url on the page won't trigger custom route matching in my app. For example, a static html file is put at path /post/hello.html, and this will make route matching arm Route::Post unmatchable

#[derive(Clone, Routable, PartialEq)]
enum Route {
    #[at("/")]
    Home,
    #[at("/post/:id")]
    Post { id: String },
    #[not_found]
    #[at("/404")]
    NotFound,
}

Steps To Reproduce

  1. Clone this repository, which stores the related codes
    git clone https://github.com/sammyne/yew-router-path-cannot-captured
    
    cd yew-router-path-cannot-captured
  2. Install tools
    rustup target add wasm32-unknown-unknown
    
    cargo install trunk wasm-bindgen-cli
  3. Start the server
    trunk serve
  4. Visit http://127.0.0.1:8080/post/hello.html,and check log in Console of DevTools.

Expected behavior
See logs post id=hello.html in Console

Screenshots
screenshot

Environment:

  • Yew version: v0.21.0
  • Yew Router version: v0.18.0
  • Rust version: 1.73.0
  • Target, if relevant: wasm32-unknown-unknown
  • Build tool, if relevant: trunk
  • OS, if relevant: Debian GNU/Linux 11 (bullseye)
  • Browser and version, if relevant: Chrome 120.0.6073.0 64-bits

What if you go to http://127.0.0.1:8080/post/hello without .html suffix? You're not getting a .html file, so the extension is not needed

What if you go to http://127.0.0.1:8080/post/hello without .html suffix? You're not getting a .html file, so the extension is not needed

Without .html suffix will match the /post/:id case. Why it cannot be matched with .html suffix?
I just wonder if the route won't be respected when there is a static file matching the routing path. @hamza1311