使用react-router获取所有可能路径的列表

时间:2014-12-26 11:54:51

标签: reactjs react-router

我想知道是否有React Router某种方式来获取路由配置的所有可能路径的列表?

例如,从中:

var routes = (
    <Route name="/">
        <DefaultRoute .../>
        <Route name="about" .../>
        <Route name="blog" .../>
    </Route>
);

我想:

["/", "/about", "/blog"]

2 个答案:

答案 0 :(得分:3)

有几种方法可以做到这一点:

  1. 最简单:通过查看道具(http.sys)将您的路线视为数组。但是,这包括许多您不一定要寻找的额外数据。

  2. 更强大:使用社区构建的工具,例如react-router-queryreact-router-to-arrayreact-router-sitemap。所有人都有相当强大的读物,你可以深入研究。

  3. 有人问了类似的问题on this thread并提供了更详细的回复。

答案 1 :(得分:2)

这似乎对我有用,使用v0.13:

public static void main(String[] args) throws IOException {
    GitHubClient client = new GitHubClient();
    client.setCredentials("xxxxxx", "xxxxx");

    int openIssue = 0;
    int closedIssue = 0;


    RepositoryService repositoryService = new RepositoryService(client);
    IRepositoryIdProvider repoId = new repositoryId("purifycss","purifycss");

    IssueService issueService = new IssueService(client);

    for(SearchIssue search : issueService.searchIssues(repoId, "all", " ")){
        System.out.println(search.getTitle() + " " + search.getState() + " " + search.getNumber());

        if(search.getState().equalsIgnoreCase("open"))
            openIssue++;

        if(search.getState().equalsIgnoreCase("closed"))
            closedIssue++;

    }

    System.out.println(openIssue + " " + closedIssue);

}