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

Lazy evaluation for routes with named parameters #23

Closed
kuy opened this issue Dec 26, 2016 · 1 comment
Closed

Lazy evaluation for routes with named parameters #23

kuy opened this issue Dec 26, 2016 · 1 comment
Labels

Comments

@kuy
Copy link
Owner

kuy commented Dec 26, 2016

Actual resolver doesn't accept a redirection to a route with named parameters.

const routes = {
  '/blog/posts/:id': ...
  '/about': '/blog/posts/42', // => undefined
}

A function, which returns a route name, can be used for a lazy evaluation.

const routes = {
  '/blog/posts/:id': ...
  '/about': () => '/blog/posts/42',
}

After building route matcher, the lazy route will be replaced by an auto-generated saga.

const routes = {
  '/blog/posts/:id': ...
  '/about': function* () {
    yield put(push('/blog/posts/42'));
  },
}

We now need something like post-process for the route definition.

@kuy kuy added the feature label Dec 27, 2016
@kuy
Copy link
Owner Author

kuy commented Jan 3, 2017

To wrap with an anonymous function is annoying. If the resolver can't find a destination, it can fallback to lazy (runtime) evaluation with wrapping a path string.

const routes = {
  '/blog/posts/:id': Post,
  '/posts/:id': '/blog/posts/:id',
  '/about': '/blog/posts/42',
  '/contact': '/blog/posts/8/edit',
}

This routes will be...

const routes = {
  '/blog/posts/:id': Post,
  '/posts/:id': Post, // OK
  '/about': function* () {
    yield '/blog/posts/42'; // Redirection
  },
  '/contact': function* () {
    yield '/blog/posts/8/edit'; // Redirection, but not found
  },
}

@kuy kuy closed this as completed Jan 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant