-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Add relative path handling to application.navigateToUrl
#78565
Add relative path handling to application.navigateToUrl
#78565
Conversation
@flash1293 could you confirm the PR addresses both issues from #78007? |
Pinging @elastic/kibana-platform (Team:Platform) |
export const parseAppUrl = ( | ||
url: string, | ||
basePath: IBasePath, | ||
apps: Map<string, App<unknown>>, | ||
currentUrl: string = window.location.href | ||
): ParsedAppUrl | undefined => { | ||
const currentOrigin = getUrlOrigin(currentUrl); | ||
if (!currentOrigin) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual diff for the changes on parseAppUrl
can be seen in this commit: e14858f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested in Chrome and the navigation using a URL like ../app/kibana#/dashboard/edf84fe0-e1a0-11e7-b6d5-4dc382ef7f5b
works fine. This fixes #77733 LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly left documentation nits
? AppNavLinkStatus.hidden | ||
: AppNavLinkStatus.visible | ||
: app.navLinkStatus!; | ||
const { updater$, mount, ...infos } = app; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think it would be safer to pick the safe properties instead of using the rest spread so that we don't forget to remove any future sensitive properties (we'll probably get a type error in the test, but still feels more brittle).
import { App, ParsedAppUrl } from '../types'; | ||
|
||
/** | ||
* Parse given url and return the associated app id and path if any app matches, or undefined if none do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Parse given url and return the associated app id and path if any app matches, or undefined if none do. | |
* Parse given URL and return the associated app id and path if any app matches, or undefined if none do. |
* Parse given url and return the associated app id and path if any app matches, or undefined if none do. | ||
* Input can either be: | ||
* | ||
* - a absolute path containing the basePath, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* - a absolute path containing the basePath, | |
* - an absolute path containing the basePath, |
* - a absolute path containing the basePath, | ||
* e.g `/base-path/app/my-app/some-path` | ||
* | ||
* - an absolute url matching the `origin` of the kibana instance (as seen by the browser), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* - an absolute url matching the `origin` of the kibana instance (as seen by the browser), | |
* - an absolute URL matching the `origin` of the Kibana instance (as seen by the browser), |
@@ -4,9 +4,11 @@ | |||
|
|||
## ApplicationStart.navigateToUrl() method | |||
|
|||
Navigate to given url, which can either be an absolute url or a relative path, in a SPA friendly way when possible. | |||
Navigate to given url in a SPA friendly way when possible (when the url will redirect to a valid application within the current basePath). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Navigate to given url in a SPA friendly way when possible (when the url will redirect to a valid application within the current basePath). | |
Navigate to given URL in a SPA friendly way when possible (when the URL will redirect to a valid application within the current basePath). |
|
||
If all these criteria are true for the given url: - (only for absolute URLs) The origin of the URL matches the origin of the browser's current location - The pathname of the URL starts with the current basePath (eg. /mybasepath/s/my-space) - The pathname segment after the basePath matches any known application route (eg. /app/<id>/ or any application's `appRoute` configuration) | ||
The method resolves pathnames the same way browsers do when resolving a `<a href>` value. The provided url can be: - an absolute url - an absolute path - a path relative to the current url (window.location.href) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method resolves pathnames the same way browsers do when resolving a `<a href>` value. The provided url can be: - an absolute url - an absolute path - a path relative to the current url (window.location.href) | |
The method resolves pathnames the same way browsers do when resolving an `<a href>` value. The provided URL can be: - an absolute URL - an absolute path - a path relative to the current URL (window.location.href) |
If all these criteria are true for the given url: - (only for absolute URLs) The origin of the URL matches the origin of the browser's current location - The pathname of the URL starts with the current basePath (eg. /mybasepath/s/my-space) - The pathname segment after the basePath matches any known application route (eg. /app/<id>/ or any application's `appRoute` configuration) | ||
The method resolves pathnames the same way browsers do when resolving a `<a href>` value. The provided url can be: - an absolute url - an absolute path - a path relative to the current url (window.location.href) | ||
|
||
If all these criteria are true for the given url: - (only for absolute URLs) The origin of the URL matches the origin of the browser's current location - The resolved pathname of the provided URL/path starts with the current basePath (eg. /mybasepath/s/my-space) - The pathname segment after the basePath matches any known application route (eg. /app/<id>/ or any application's `appRoute` configuration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If all these criteria are true for the given url: - (only for absolute URLs) The origin of the URL matches the origin of the browser's current location - The resolved pathname of the provided URL/path starts with the current basePath (eg. /mybasepath/s/my-space) - The pathname segment after the basePath matches any known application route (eg. /app/<id>/ or any application's `appRoute` configuration) | |
If all these criteria are true for the given URL: - (only for absolute URLs) The origin of the URL matches the origin of the browser's current location - The resolved pathname of the provided URL/path starts with the current basePath (eg. /mybasepath/s/my-space) - The pathname segment after the basePath matches any known application route (eg. /app/<id>/ or any application's `appRoute` configuration) |
💚 Build SucceededMetrics [docs]@kbn/optimizer bundle module count
async chunks size
page load bundle size
History
To update your PR or re-run it, just comment with: |
…79139) * split application utilities and associated tests to distinct files * do not match app if path does not start with the basePath * add relative paths support to `navigateToUrl` * add null-check error * update generated doc * nits on doc
Summary
Fix #78007
navigateToUrl
to prepend the basePath when invoking it with a non basePath-prefixed absolute path to a valid app instead of redirecting to the given absolute path.navigateToUrl
, that follows the browser's<a href>
resolution logic.relative path
term instead of the correctabsolute path
one.Checklist