Skip to content

Conversation

@jakewski
Copy link
Contributor

@jakewski jakewski commented Feb 1, 2022

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
Copy link
Contributor Author

jakewski commented Feb 3, 2022

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 {'': (...) => {...}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants