mercredi 1 avril 2020

Having an optional prefix in ember routes

Problem

The app has to have root prefix that is optional. The prefix also has a dynamic segment.

Example

The content of

/posts/1 and /account/123/posts/1 has to load the same route and template.

where /account/123 is the prefix. 123 is a dynamic segment of the prefix.

Requirement

  1. All the urls has to be accessible with and without the prefix.
  2. When prefix route is loaded , all single page transitions has to be in context of prefix-urls.

    /account/123/post/1 to /account/123/post/2

  3. When non-prefix route is loaded , all single page transitions has to be in context of non-prefix-urls.

    /post/1 to /post/2

Constraints

  1. The existing codebase has routes without the prefix urls.
  2. As controllers,routes,tempaltes already exist in routes without prefix , the solution has to reuse the existing code.

Expected Solution

  1. All functions making spa transitions has to see the window.location context and make transition to prefix or non-prefix path. This will include functions as transitionTo,replaceWith,linkTo helper,etc

    Since the existing link-to helper,etc, will have route name as post.detail (non-prefix routes)

  2. Has to have minimal code changes in the existing controller , routes, templates.

Example of Existing Routes

NewRouter.map(function() {
  this.route('posts', function() {
    this.route('detail',{path: "/:id"});

    this.route('comments', function() {
        this.route('detail',{path: "/:id"});
    });
  });

});

The controllers, routes, templates already exist for post, post.detail, comments, comment.detail.




Aucun commentaire:

Enregistrer un commentaire