Skip to content

fix(v2): more consistent route config generation - #1946

Merged
endiliey merged 6 commits into
masterfrom
endi/docsroute
Nov 8, 2019
Merged

endiliey merged 6 commits into
masterfrom
endi/docsroute

Conversation

@endiliey

@endiliey endiliey commented Nov 7, 2019 •

Copy link
Copy Markdown
Contributor

Motivation

Ensure routes config generation to be more consistent in ordering. Nested routes should have params and be placed last in routes.js.

Consider a scenario of having a src/pages/docs.js. This means

Before

// routes.js
export default [
{
  path: "/docs",
  component: ComponentCreator("/docs")
},
  {
    path: "/docs",
    component: ComponentCreator("/docs"),
    routes: [
      {
        path: "/docs/advanced-themes",
        component: ComponentCreator("/docs/advanced-themes"),
        exact: true
      },
      {
        path: "/docs/advanced-plugins",
        component: ComponentCreator("/docs/advanced-plugins"),
        exact: true
      },
    ]
  },
  {
    path: "*",
    component: ComponentCreator("*")
  }
];

Component creator will be confused because /docs can resolve to DocPage and src/pages/docs.js. We should be using a : params instead as suggested in https://reacttraining.com/react-router/core/api/Route/route-props

{
    path: "/docs/:route",
    component: ComponentCreator("/docs/:route"),
}

Another thing is due to async nature of addRoute, sometimes generated route can be inconsistent and sometimes some nested route takes precedence.
We can sort it.

Extra benefit: This will allow user to create src/pages/docs.js to create custom docs page for /docs
test
.

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

  • Netlify
  • Create src/pages/docs.js and src/pages/docs/super.js. Above route is accessible and not 404.

@endiliey
endiliey requested a review from yangshun as a code owner November 7, 2019 08:02
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Nov 7, 2019
@docusaurus-bot

Copy link
Copy Markdown
Contributor

@docusaurus-bot

Copy link
Copy Markdown
Contributor

@docusaurus-bot

Copy link
Copy Markdown
Contributor

@docusaurus-bot

Copy link
Copy Markdown
Contributor

@docusaurus-bot

docusaurus-bot commented Nov 7, 2019 •

Copy link
Copy Markdown
Contributor

@docusaurus-bot

docusaurus-bot commented Nov 7, 2019 •

Copy link
Copy Markdown
Contributor

@endiliey
endiliey merged commit fc4928f into master Nov 8, 2019
@endiliey
endiliey deleted the endi/docsroute branch November 8, 2019 04:55
@endiliey endiliey added the pr: maintenance This PR does not produce any behavior differences to end users when upgrading. label Dec 3, 2019
mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
* fix(v2): more consistent route config generation

* nits

* snapshot

* address review & test upd

* reduce 2xloop -> 1x loop in docs plugin

* nits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: maintenance This PR does not produce any behavior differences to end users when upgrading.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants