app-route icon indicating copy to clipboard operation
app-route copied to clipboard

Question: Who should handle 404 pages?

Open ymaz opened this issue 8 years ago • 11 comments

Hi, it's not a issue at all, it's more just a questing/best practices manual/discussion.

So, who should handle 404 page in Polymer app, which using <app-route> for the routing?

I mean, when user typed something incorrect which is not relevant to any page/view. Which element should be responsible for redirect?

For example, I'm using combo <app-route> + <iron-pages>. I've spotted that <iron-pages> support fallbackSelection attr for fallback view.

Okay, theoretically, i can do like this:

    <iron-pages role="main" selected="[[page]]" attr-for-selected="name" selected-attribute="visible" fallback-selection="404">
      <!-- home view -->
      <shop-home name="home" categories="[[categories]]"></shop-home>
      <!-- list view of items in a category -->
      <shop-list name="list" route="[[subroute]]" offline="[[offline]]"></shop-list>
      <!-- detail view of one item -->
      <shop-detail name="detail" route="[[subroute]]" offline="[[offline]]"></shop-detail>
      <!-- 404 page view -->
      <shop-404page name="404"></shop-404page>
    </iron-pages>

This solution will work okay for top level navigation, like /list, /details but what if something goes wrong on the second level? Example /list/blabla and etc.?

How I should handle this cases? Or i need to write some kind of _pageResolver(page) method which will receive the page string, and tries to find that page in already pre-defined router-config object/array, and after that passed the value into <iron-pages> otherwise set to 404?

Many thanks and please feel free to share you opinion regarding that.

ymaz avatar Jul 05 '16 18:07 ymaz