panel icon indicating copy to clipboard operation
panel copied to clipboard

Single-page path routing

Open jakewski opened this issue 3 years ago • 1 comments

The current panel router only works on hash fragments. This PR enables us to use the same router syntax on paths as well to allow single-page path routing within a panel app.

We're maintaining backward compatibility with old hash-only routes, and will detect the new path-routing schema:

{
  /**
 * Handler that takes a state update and named parameters from a matched path and hash expression.
 */
export type PathRouteHandler = (
  stateUpdate: object,
  pathParams: string[],
  hashParams: string[],
) => object | null | undefined;

/** Path + hash routing support */
export interface RouteDefinition {
  /** Root path expression where component lives, defaults to '/' */
  basePath?: string;
  paths: Array<{
    /** Path expression relative to the basePath */
    pathName: string;
    /** Any hash routes and their handlers */
    hashRoutes: {
      [route: string]: PathRouteHandler | string;
    };
  }>;
}
}

Furthermore, for backward compatibility, router.navigate will be aliased to hashNavigate, and we will expose a new method called pathNavigate as the path version.

jakewski avatar Feb 01 '22 20:02 jakewski

after using this for a bit, I think I may implement an optional handler fn instead of hashRoutes to avoid redundant index hash route definitions like {'': (...) => {...}}

jakewski avatar Feb 03 '22 17:02 jakewski