: https://github.com/elliottsj/react-router-query
그것은 (즉 getChildRoutes
/getIndexRoute
) 비동기 경로를 처리하고 단지 배열을하지 제공 할 수 경로 (fullPath
)를 포함하는 "FlatRoute"개체 배열과 각 경로의 원래 속성 및 "부모"경로의 배열 :
fullPath: '/'
도
fullPath: '/author'
에 대한 "FlatRoute"개체가 없습니다 : 전용 "잎"루트는 결과에 포함되어
import { query } from 'react-router-query';
const routes = (
<Route path="/" component={App}>
<Route path="author" component={Author}>
<Route path="about" component={About} />
</Route>
<Route path="users" component={Users} />
</Route>
);
query('/', routes, (error, result) => {
expect(result).toEqual([
{
fullPath: '/author/about'
component: About,
parents: [
{ path: '/', component: App },
{ path: 'author', component: Author },
],
},
{
fullPath: '/users'
component: Users,
parents: [
{ path: '/', component: App },
],
},
]);
});
참고. 이것은 자식 경로의 레이아웃으로 만 사용되는 경로를 포함하지 못하게하는 것입니다.
<Route path="/" component={App}>
<Route path="posts" component={PostLayout}>
<Route path="1" component={Post1} />
<Route path="2" component={Post2} />
<Route path="3" component={Post3} />
</Route>
</Route>
당신이 /posts
에 대한 FlatRoute를 원하는 경우
, 단순히 포함
IndexRoute
:
<Route path="/" component={App}>
<Route path="posts">
<IndexRoute component={Posts} />
<Route path="1" component={Post1} />
<Route path="2" component={Post2} />
<Route path="3" component={Post3} />
</Route>
</Route>
이에 대한 사용 사례 무엇인가? – eenagy
정적 사이트 생성을 위해 webpack 용 플러그인을 사용하고 싶습니다. 즉, github.io에 내 앱을 게시하고 반응 라우터를 사용하고 있습니다. 이 프로젝트를 참조하십시오 : https://github.com/markdalgleish/static-site-generator-webpack-plugin. 그들은 노선의 배열을 그들의 입장으로 기대합니다. –
여기 Sitemap [react-router-sitemap] (https://www.npmjs.com/package/react-router-sitemap)을 생성하는 사이트이지만, 귀하가 간단하게 줄일 수 있다고 생각합니다. , 더 복잡한 경로가 될 때까지 – eenagy