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

context.path gets overwritten by route.path while resolving #69

Closed
kleinspire opened this issue Nov 12, 2016 · 2 comments · Fixed by #83
Closed

context.path gets overwritten by route.path while resolving #69

kleinspire opened this issue Nov 12, 2016 · 2 comments · Fixed by #83

Comments

@kleinspire
Copy link

kleinspire commented Nov 12, 2016

resolve.js line 31:

const newContext = Object.assign({}, context, value);

@kleinspire
Copy link
Author

kleinspire commented Nov 12, 2016

in the root route I want to do something like this:

export default {

  path: '/',

  children: [
    require('./protected1').default,
    require('./protected2').default,
    require('./login').default,
  ],

  async action({ path, query, next }) {
    const route = await next();

    if (path !== '/login' && !isAuthenticated()) {
      route.redirect = '/login';
    }

    return route;
  }
}

And I'm resolving it with:

const route = await UniversalRouter.resolve(routes, {
  path: req.path
});

if (route.redirect) {
  res.redirect(route.status || 302, route.redirect);
  return;
}

When navigating to http://mywebsite/login I was expecting path to be '/login' in the root route action, but it's always '/'.

As a workaround I'm passing additional _path property to the context and using that instead:

const route = await UniversalRouter.resolve(routes, {
  path: req.path,
  _path: req.path
});

@frenzzy
Copy link
Member

frenzzy commented Mar 27, 2017

Since v3.0.0 you can use context.url instead of _path. More info about context see in docs.

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