url-routingcyclejsswitch-path

Can't switchPath 404s, fails to capture wildcard route


Feeding this into switchPath

  const Routes = {
    "/": Home,
    "/login": Login,
    '*': function(){return {DOM: xs.of(<h1> 404</h1>)}}
  }

navigating to /lossgin will log that current route/path is "/".


Solution

  • This appears to be a problem with switch-path. (And nothing to do with CycleJS history)

    See this switch-path issue and this pull request.

    Simply put, the wildcard * does not get captured when route '/' is in use and there are no nested routes. For example:

    const { path, value } = switchPath("/lossgin", {
      "/": 123,
      "/login": 456,
      "*": 789
    });
    

    console.log(path, value) produces:

    / 123
    

    A work-around is to change your login route to a nested route:

    const { path, value } = switchPath("/lossgin", {
      "/": 123,
      "/login": {"/": 456}, // <-- nested route
      "*": 789
    });
    

    console.log(path, value) produces:

    /lossgin 789
    

    See code example here.