: https://github.com/elliottsj/react-router-query
O (yani getChildRoutes
/getIndexRoute
) asenkron yolları ele ve sadece bir dizi değil sağlar olabilir yollar, ancak yol (fullPath
), artı her bir yolun özgün özelliklerinin tümünü ve "ana" yollar dizisini içeren bir "FlatRoute" nesnesi dizisi:
fullPath: '/'
ne de
fullPath: '/author'
için hayır "FlatRoute" nesne vardır: Yalnızca "yaprak" yolları sonucu bulunur
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 },
],
},
]);
});
Not. Bu, yalnızca çocuk güzergâhları için bir düzen olarak kullanılan güzergâhlar dahil, örneğin;
<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>
Eğer /posts
için FlatRoute istiyorsanız
, basitçe dahil bir
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>
Bunun kullanım durumu nedir? – eenagy
Statik site üretimi için web paketi için bir eklenti kullanmak istiyorum. Kısacası, uygulamanızı github.io'da yayınlamak istiyorum ve tepki veren yönlendiriciyi kullanıyorum. Bu projeye bakın: https://github.com/markdalgleish/static-site-generator-webpack-plugin. Girişleri olarak bir dizi rota beklerler. –
burada site haritası oluşturan [tepki-yönlendirici-site haritası] (https://www.npmjs.com/package/react-router-sitemap), ama sanırım basit bir azaltma ile daha iyi durumdasınız (dediğiniz gibi) Daha karmaşık rotalarınız olana kadar, – eenagy