Class RouterAbstract

GoJS® Diagramming Components
version 3.0.2
by Northwoods Software®


A Router is a class that is responsible for the paths of a collection of Links.

Some routers modify the Link.points of some Links in ways that the default routing provided by Link.computePoints cannot, because the latter method only considers the properties of the Link and its connected ports -- not other Nodes or Links.

Some routers modify other aspects of Links.

The most commonly used Router is the AvoidsLinksRouter extension in the extensions or extensionsJSM directories.

The Router class is abstract and does not really provide any functionality of its own. You can install a Router subclass by constructing and initializing it and then inserting it into the Diagram.routers list.

myDiagram.routers.add(new AvoidsLinksRouter());

A Router that has been installed will automatically operate on the Links of Groups or the top-level Links of the Diagram.

You can disable a Router by setting its isEnabled property to false, or by overriding canRoute to decide when it should operate.

Your subclass of Router should override routeLinks method in order to examine the Links implicitly given to the method.





  • Don't construct this directly -- this is an abstract class.

    Returns Router


  • Gets or sets the Diagram this router is associated with. Routers cannot be shared.

  • Gets or sets whether this router is enabled.

  • Gets or sets whether this router runs during real-time operations, such as dragging or resizing. The default is true.

  • Gets or sets the name of this router.


  • Determine for the given collection if this router can route.

    Adding a Router to the Diagram will cause the Diagram to call canRoute for every group recursively, and finally for the Diagram itself.

    By default this just returns the value of isEnabled. If true, routeLinks will be called on each collection.

    An override of this method should return false if isEnabled is false.

    This method is only called by the Diagram. If using a Router without adding it to a Diagram, this method will never be called.


    Returns boolean

  • If this router has been added to a diagram, calling this method will ensure the Diagram re-runs all routing.

    The router should call this method when setting properties that might require the router to re-run when values change.

    Returns void

  • Route the links for a given collection (Group or Diagram). By default this is called in a depth-first manner on every Group in the Diagram, and then the Diagram itself. If a layout occurred for a Group or a Diagram, this is called immediately afterwards if canRoute returns true.

    It is common to route all links in each Group's Group.memberParts, and then all top-level links in the Diagram.links collection. (All Links that have Part.containingGroup === null)

    The first argument is a Set of Links that the Diagram has collected which it considers invalid. Typically, these are the only links that need routing. Since routeLinks is called with each Group and then the Diagram, you should check the Part.containingGroup on each Link to ensure it matches:

     public routeLinks(links: GSet<Link>, coll?: Diagram | Group): void {
    const container = coll instanceof Diagram ? null : coll;
    const it = links.iterator;
    while ( {
    const link = it.value;
    // Only operate on links that are in the corresponding collection, if one is given
    if (coll && link.containingGroup !== container) continue;
    . . .

    This method should not check the canRoute predicate.


    • links: Set<Link>

      The set of links that were recently recomputed, which may need routing.

    • Optional coll: Diagram | Group

      A Diagram or Group on which the Router will operate. When calling a router manually, this does not need to be specified.

    Returns void