krasimir / navigo

A simple vanilla JavaScript router.
MIT License
2.75k stars 250 forks source link

case sensitive routes #312

Closed tpezzelle closed 2 years ago

tpezzelle commented 2 years ago

i've seen the 2 other posts regarding case sensitive routes and have tried the

Navigo.MATCH_REGEXP_FLAGS = 'i'

but to no avail... is there any additional info on how/when/where to implement this assignment so that it works?

tpezzelle commented 2 years ago

in case anyone else wanders across this using IIS.... here's what seems to be working for me. add the block to in web.config. the first rule does a redirect to the route, but in lower case. the second rule does a rewrite to assure that all routes load the default.html page.

<rewrite>
  <rules>
    <rule name="ToLowerCase" stopProcessing="true">
      <match url="[A-Z]" ignoreCase="false" />
      <action type="Redirect" url="{ToLower:{URL}}" />          
    </rule>
    <rule name="SPA Routes" stopProcessing="true">
      <!-- match everything by default -->
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
      </conditions>
      <action type="Rewrite" url="/default.html" />
    </rule>
  </rules>
</rewrite>