Polymer / pwa-helpers

Small helper methods or mixins to help you build web apps.
BSD 3-Clause "New" or "Revised" License
439 stars 48 forks source link

feature: Add a redirects mapping parameter #38

Closed Dabolus closed 5 years ago

Dabolus commented 5 years ago

This is to be considered a proposal/proof of concept, not a real PR.

The router helper is really great and useful, and I've been using it a lot. However, almost every time I use it, I also find myself having to implement some sort of redirect (for example, redirecting users from / to /view1). My proposal is to add an optional "redirects mapping" parameter, that will automatically handle redirects passed to it. What do you think? Would it add too much complexity?

Example usage of my current implementation:

installRouter(callback, [
  {
    from: '/',
    to: '/view1'
  },
  {
    // Also supports arrays
    from: [
      '/randompage1',
      '/randompage2'
    ],
    to: '/view2'
  }
]);
keanulee commented 5 years ago

Interesting idea, though this wouldn't handle cases where users cmd+click's to open in new tab or if the user navigates directly to the "from" URL. Those cases would have to be handled by some script, perhaps in a history.replaceState() in the function you pass to installRouter().

Dabolus commented 5 years ago

Actually, this check should handle those cases too, as it is run when the router is installed

googlebot commented 5 years ago

So there's good news and bad news.

:thumbsup: The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

:confused: The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.