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

i18n paths #84

Closed
alopes opened this issue Mar 23, 2017 · 2 comments · May be fixed by #86
Closed

i18n paths #84

alopes opened this issue Mar 23, 2017 · 2 comments · May be fixed by #86

Comments

@alopes
Copy link

alopes commented Mar 23, 2017

So I've been banging my head on this one.

Using react-intl, how can I go from

export default {

  path: '/myurl',

to

export default {

  path: formatMessage({ id: route.myurl }),

Thanks! #

@frenzzy
Copy link
Member

frenzzy commented Mar 23, 2017

Can you describe a more realistic use case? What kind of page?

For example for static routes with unicode characters need to use encoded path (because HTTP does not allow characters outside the ASCII range):

const route = {
  path: '/caf%C3%A9', // encodeURI('/café') or `/${encodeURIComponent('café')}`
  action(context) {
    console.log(context.path) // => '/caf%C3%A9'
  },
};

const location = new URL('http://example.com/café'); // like window.location
location.pathname // => '/caf%C3%A9'
UniversalRouter.resolve(route, location.pathname);

But in your case probably need to use dynamic path params:

const route = {
  path: '/:name',
  action(context, params) {
    if (params.name === 'café') { // or check for any localized paths
      return 'page';
    }
    return null; // page not found
  }
};

@alopes
Copy link
Author

alopes commented Mar 23, 2017

@frenzzy, thanks for the feedback. With your help, I was able to get it running!

@alopes alopes closed this as completed Mar 23, 2017
@frenzzy frenzzy mentioned this issue Mar 27, 2017
20 tasks
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

Successfully merging a pull request may close this issue.

2 participants