两个通配符路由在反应路由中意味着什么?

What do two wildcard routes mean in react-routing?

我试图通过 kirasoft 理解 react-starter-kit 并注意到他们的路由有两个条目用于 '*' 通配符路由。为什么有两个,优先顺序是什么?第一条路线似乎总体上设置了应用程序,然后第二条路线似乎触发了默认的内容处理程序……两者都被触发了,如果是的话,两者之间的逻辑是什么,它们是否都按顺序触发并附加以某种方式一起响应?

import React from 'react';
import Router from 'react-routing/src/Router';
import http from './core/HttpClient';
import App from './components/App';
import ContentPage from './components/ContentPage';
import ContactPage from './components/ContactPage';
import LoginPage from './components/LoginPage';
import RegisterPage from './components/RegisterPage';
import NotFoundPage from './components/NotFoundPage';
import ErrorPage from './components/ErrorPage';

const router = new Router(on => {
  on('*', async (state, next) => {
    const component = await next();
    return component && <App context={state.context}>{component}</App>;
  });

  on('/contact', async () => <ContactPage />);

  on('/login', async () => <LoginPage />);

  on('/register', async () => <RegisterPage />);

  on('*', async (state) => {
    const content = await http.get(`/api/content?path=${state.path}`);
    return content && <ContentPage {...content} />;
  });
})

第一个 catch-all 路由中的关键行是 await next() 它将提供对下一个组件的引用 return 从路由树更远的匹配项开始,然后插入为 child 和 <App context={state.context}>{component}</App>。在路由不匹配 '/contact''/login''/register' 的所有情况下,第二个 catch-all 将 return child。您可以想象在树的下方进一步 catch-all "children" 以通过路由进行更深层次的组件嵌套。