Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single-page path routing #139

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Single-page path routing #139

wants to merge 9 commits into from

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.

None yet

1 participant