Can't switchPath 404s,抓取通配符路由失败

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

将其输入 switchPath

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

导航到 /lossgin 将记录当前 route/path 是“/”。

这似乎是 switch-path. (And nothing to do with CycleJS history)

的问题

查看此切换路径 issue and this pull request

简而言之,通配符 * 在路由 '/' 正在使用且没有嵌套路由时不会被捕获。例如:

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

console.log(path, value) 产生:

/ 123

解决方法 是将您的 login 路由更改为嵌套路由:

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

console.log(path, value) 产生:

/lossgin 789

See code example here.