Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds notes about HOC to handle client routing #3168

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updates notes about server config
  • Loading branch information
gregorskii authored Dec 9, 2017
commit a604589bf8cc37e4ed20ffe22252f9534967c1d2
19 changes: 16 additions & 3 deletions docs/docs/creating-and-modifying-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ exports.onCreatePage = async ({ page, boundActionCreators }) => {

### Client Route Params

In order to make a `detail` page at `/widgets/view/ID` and extract the `ID` param, we will need to configure client only routes.
In order to make a "detail" page at `/widgets/view/ID` resolve and extract the `ID` param, we will need to configure client only routes.

**Build config:**

Expand All @@ -175,8 +175,7 @@ exports.onCreatePage = async ({ page, boundActionCreators }) => {
return new Promise((resolve, reject) => {
if (/view/.test(page.path)) {
// Gatsby paths have a trailing `/`
page.path = `${page.path}:id`;
page.matchPath = page.path;
page.matchPath = `${page.path}:id`;
}

createPage(page);
Expand All @@ -185,6 +184,20 @@ exports.onCreatePage = async ({ page, boundActionCreators }) => {
};
```

**Server:**

When creating links to these view/id pages using react router or any pushstate the pages will resolve until the user hard refreshes the page. This is due to your backend server not knowing how to handle the route.

Configuration is going to be required to make these pages work on production. Results may vary depending on deployment but a simple use case for NGINX:

```
location ~ "([a-z]*)\/view\/(\d*)$" {
try_files $uri /$1/view/index.html;
}
```

This directive will provide the `widgets/view/index.html` file for any request like (widgets)/view/1. It will also support other pages by matching the first level of the URL, example http://sitename/sprockets/view/1.

**Client:**

Extracting path params from the route on the client requires that you add a `react-router` `<Route>` in your component.
Expand Down