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

Updating from version 1.5.0 to ^1.6.0 breaks route redirect to child route #619

Closed
Krussicus opened this issue Sep 6, 2018 · 8 comments · Fixed by #626
Closed

Updating from version 1.5.0 to ^1.6.0 breaks route redirect to child route #619

Krussicus opened this issue Sep 6, 2018 · 8 comments · Fixed by #626

Comments

@Krussicus
Copy link

I'm submitting a bug report

  • Library Version:
    ^1.6.0

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    9.0.0 (varies across my team but results are the same)

  • NPM Version:
    6.4.0 (varies across my team but results are the same)
  • JSPM OR Webpack AND Version
    Webpack 4.17.2
  • Browser:
    Haven't tested every browser but confirmed for Chrome and Firefox

  • Language:
    ESNext

Current behavior:
Using a route redirect to navigate to a nested(?) child route no longer works when updating aurelia-router from 1.5.0 to ^1.6.0. The broken behaviour varies slightly between the two patch-pre versions, 1.6.0 and 1.6.2, currently used within my company. Both versions seem to just silently fail, no errors emitted, and fallback to the default (blank) child route. Additionally, 1.6.2 appends the name(?) of the child route as a query string, e.g. childRoute=products, to the URL.

Several other packages also have differing version (I've supplied the package-lock.json files) so there's a chance aurelia-router is not the cause of the issue but it seems to be the most likely candidate.

Expected/desired behavior:

  • What is the expected behavior?
    I've created a Gist, which seems to work, to demonstrate the basic behaviour.

  • What is the motivation / use case for changing the behavior?
    To be able to navigate to a child route using the main router.navigation, as per standard navbar implementation.

I'm not sure how to update the packages for the Gist to reproduce the bug so I've provided the different package-lock.json files we're using along with the package.json.
npm-config.zip

If there are any alternative solutions that you can recommend for this use-case, I'm open to suggestions. I would prefer to keep the solution as simple as possible while achieving similar, if not the same, results.
I found this solution, which seems similar, but it seems overly complex compared to using a redirect. It also looks like there's a potential performance hit.

Any help with this matter is appreciated.
Thanks in advanced for your time! :)

@RichTeaTime
Copy link

This seems to be linked to changes to _buildNavigationPlan in #623 and later. The GistRun is using an aurelia.js bundle prior to this version so can't reproduce it 👎 (is there an up to date version anywhere?)

The STRs in the current aurelia/router are pretty simple:

Top Level router:
{ route: 'shortcut', redirect:'/myModule/actualPath/actualPage'}

Go to:
#/shortcut

Expected redirect:
#/myModule/actualPath/actualPage.

Actual redirect:
#/myModule?childRoute=actualPath%2FactualPage

@davismj
Copy link
Member

davismj commented Oct 31, 2018

Try here. We're working on updating the documentation and getting this working better.

https://codesandbox.io/s/kmlj7m2px5

@johan-v-r
Copy link

Thanks for the feedback @RichTeaTime. We have created a new repo to replicate the issue as described with the latest packages.

@davismj not sure about that link? Looks like it's got some react source in there..?

@davismj
Copy link
Member

davismj commented Nov 1, 2018

Sorry about that, try again.

@johan-v-r
Copy link

No problem, you can see the issue replicated here: https://codesandbox.io/s/y735958pkv

@johan-v-r
Copy link

Updating the href from '#/products' to '#/arrivals/products' to match the redirect value seems to do the trick. Everything else still stays the same, see my updated sandbox.

I remember having the exact same issue with aurelia-router 1.6.1 that "fallback to the default (blank) child route", however I can't replicate that anymore either, and the href update seems to work for all mentioned versions.

@Krussicus please have a look if this works for you.

@Krussicus
Copy link
Author

Krussicus commented Nov 2, 2018

@johan-v-r , this just changes the link to navigate directly to the child route, instead of using the redirect.
If the URL for the route with the redirect is used, the issue is still encountered, as seen here.
The issue also still exists when using router.navigateToRoute('products').

While this works fine, if one is just after a nav link, it feels a bit wrong to set up a route in this case.
This also doesn't solve the issue if one is trying to redirect an existing route, which may have considerations like browser bookmarks, etc. associated with it, to a new location within the app.

@RichTeaTime
Copy link

As we're generating these redirects from handleUnknownRoute in the AppRouter, we're now working around this by redirecting to another page (e.g. {redirect:'the-redirector', settings:myRouteConfig}) and then generating a Redirect there, e.g.

canactivate(p, d, instruction) {
  return Redirect(instruction.config.settings.redirect);
}

and this does work for redirecting to the child-router. Advantage with this is that it's just a one-liner that can be removed once this issue closes.

For us, as our RouterConfigs are being generated that's the most simple workaround as we just wrap the return value from the handleUnknownRoutes callback, meaning that we can just remove this one line once this issue is fixed in the framework :-)

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.

4 participants