riot / route

Simple isomorphic router
MIT License
212 stars 40 forks source link

Router captures all links regardless of base path #172

Closed jfbrennan closed 11 months ago

jfbrennan commented 1 year ago

I'm not able to get this to work

<app>
  <router-hoc base="/app">
    <route-hoc path="(.*)">
      <my-sitenav route="{route}"></my-sitenav>
    </route-hoc>
    <route-hoc path="/app/:tab?">
      <my-tabs route="{route}"></my-tabs>
    </route-hoc>
  </router-hoc>
</app>

And inside my-sitenav.riot I have a link to take the user over to the main website

<a href="/">Home (should hit the "/" route on Express server, but it does not.)<a>

In fact, every link inside <router-hoc base="/app"> seems to be captured by Riot Router

<app>
  <router-hoc base="/app">
    <a href="/">Home (should hit the "/" route on Express server, but it does not.)<a>
    <a href="/foo">should hit the "/foo" route on Express server, but it does not<a>
    <a href="/bar/baz">should hit the "/bar/baz" route on Express server, but it does not<a>

    <route-hoc path="(.*)">
      <my-sitenav route="{route}"></my-sitenav>
    </route-hoc>
    <route-hoc path="/app/:tab?">
      <my-tabs route="{route}"></my-tabs>
    </route-hoc>
  </router-hoc>
</app>
jfbrennan commented 1 year ago

Router is setting base to / inside getBase(). The call to getAttribute(BASE_ATTRIBUTE_NAME) returns undefined, but this.el.attributes.base is set to /app...

GianlucaGuarini commented 1 year ago

I think that you have found a bug. I will patch it asap. Please for now just use <router-hoc base={"/app"}> instead, this should work as expected. Thank you for your help

jfbrennan commented 1 year ago

That worked, thanks! If I have time I will try to debug further and send a PR.