Skip to content

Support for client routes #93

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

Open
igor-krupa opened this issue Jan 9, 2020 · 7 comments
Open

Support for client routes #93

igor-krupa opened this issue Jan 9, 2020 · 7 comments

Comments

@igor-krupa
Copy link

igor-krupa commented Jan 9, 2020

Hello.
Is there support for client routes?
I've noticed that everything that's wrapped in Router from @reach/router is not being displayed at all when using this plugin.
It's displayed only on index page when using redirect: false option (so on / route). But every other language index doesn't display what's in Router.
Is there maybe some option for that?
I'm not using any other plugin that can conflict with that.

@igor-krupa igor-krupa changed the title Support for dynamic routes Support for client routes Jan 9, 2020
@Steffi3rd
Copy link

+1

Yes please.

@mmmoli
Copy link

mmmoli commented Mar 30, 2020

Did anyone come up with anything?

@mmmoli
Copy link

mmmoli commented Mar 30, 2020

This worked for me: (note: I'm re-routing to "/me"):


const re = /^\/([\w-]+)\/me/;
exports.onCreatePage = async ({ page, actions }) => {
  const { createPage } = actions;

  const match = re.exec(page.path);
  // Only update the `/me` page.
  if (match) {
    // page.matchPath is a special key that's used for matching pages
    // with corresponding routes only on the client.
    page.matchPath = `${match[0]}/*`;
    // Update the page.
    createPage(page);
  }
};

@jayjayzheng
Copy link

Thanks @mmmoli ! Worked out perfectly for me

@blazelon
Copy link

Extending @mmmoli 's solution, for multiple routes the following could be added to gatsby-node.js

exports.onCreatePage = ({ page, actions }) => {
  const { createPage } = actions
  const matchPathProducts = page.path.match(/^\/([\w-]+)\/products/)
  const matchPathProduct = page.path.match(/^\/([\w-]+)\/product/)
  const matchPathUser = page.path.match(/^\/([\w-]+)\/user/)

  if (matchPathProducts) {
    page.matchPath = `${matchPathProducts[0]}/*`
    createPage(page)
  } else if (matchPathProduct) {
    page.matchPath = `${matchPathProduct[0]}/*`
    createPage(page)
  } else if (matchPathUser) {
    page.matchPath = `${matchPathUser[0]}/*`
    createPage(page)
  }
}

@ltremago
Copy link

+1

@mcarnoky001
Copy link

mcarnoky001 commented Dec 22, 2021

Worked above solutions but needed to add this to the router, for my "app" page, to listen for path change:
<Router basepath={`${intl.locale}`+"/app"}>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants