Make the Web app aware of its context root
This commit is contained in:
@@ -38,7 +38,7 @@ export class AbstractApp extends Component {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new App instance.
|
||||
* Initializes a new AbstractApp instance.
|
||||
*
|
||||
* @param {Object} props - The read-only React Component props with which
|
||||
* the new instance is to be initialized.
|
||||
@@ -334,13 +334,7 @@ export class AbstractApp extends Component {
|
||||
// (2) A replace function would be provided to the Route in case it
|
||||
// chose to redirect to another path.
|
||||
this._onRouteEnter(route, nextState, pathname => {
|
||||
// FIXME In order to minimize the modifications related to the
|
||||
// removal of react-router, the Web implementation is provided
|
||||
// bellow because the replace function is used on Web only at the
|
||||
// time of this writing. Provide a platform-agnostic implementation.
|
||||
// It should likely find the best Route matching the specified
|
||||
// pathname and navigate to it.
|
||||
window.location.pathname = pathname;
|
||||
this._openURL(pathname);
|
||||
|
||||
// Do not proceed with the route because it chose to redirect to
|
||||
// another path.
|
||||
|
||||
@@ -14,6 +14,27 @@ export class App extends AbstractApp {
|
||||
*/
|
||||
static propTypes = AbstractApp.propTypes
|
||||
|
||||
/**
|
||||
* Initializes a new App instance.
|
||||
*
|
||||
* @param {Object} props - The read-only React Component props with which
|
||||
* the new instance is to be initialized.
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
...this.state,
|
||||
|
||||
/**
|
||||
* The context root of window.location i.e. this Web App.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
windowLocationContextRoot: this._getWindowLocationContextRoot()
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Inits the app before component will mount.
|
||||
*
|
||||
@@ -35,6 +56,22 @@ export class App extends AbstractApp {
|
||||
return window.location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the context root of this Web App from window.location.
|
||||
*
|
||||
* @private
|
||||
* @returns {string} The context root of window.location i.e. this Web App.
|
||||
*/
|
||||
_getWindowLocationContextRoot() {
|
||||
const pathname = this._getWindowLocation().pathname;
|
||||
const contextRootEndIndex = pathname.lastIndexOf('/');
|
||||
|
||||
return (
|
||||
contextRootEndIndex === -1
|
||||
? '/'
|
||||
: pathname.substring(0, contextRootEndIndex + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigates to a specific Route (via platform-specific means).
|
||||
*
|
||||
@@ -53,6 +90,7 @@ export class App extends AbstractApp {
|
||||
= path.replace(
|
||||
/:room/g,
|
||||
store.getState()['features/base/conference'].room);
|
||||
path = this._routePath2WindowLocationPathname(path);
|
||||
|
||||
// Navigate to the specified Route.
|
||||
const windowLocation = this._getWindowLocation();
|
||||
@@ -69,4 +107,22 @@ export class App extends AbstractApp {
|
||||
windowLocation.pathname = path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a specific Route path to a window.location.pathname.
|
||||
*
|
||||
* @param {string} path - A Route path to be converted to/represeted as a
|
||||
* window.location.pathname.
|
||||
* @private
|
||||
* @returns {string} A window.location.pathname-compatible representation of
|
||||
* the specified Route path.
|
||||
*/
|
||||
_routePath2WindowLocationPathname(path) {
|
||||
let pathname = this.state.windowLocationContextRoot;
|
||||
|
||||
pathname.endsWith('/') || (pathname += '/');
|
||||
pathname += path.startsWith('/') ? path.substring(1) : path;
|
||||
|
||||
return pathname;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,15 +76,18 @@ class WelcomePage extends AbstractWelcomePage {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the domain name.
|
||||
* Returns the URL of this WelcomePage for display purposes. For
|
||||
* historic/legacy reasons, the return value is referred to as domain.
|
||||
*
|
||||
* @private
|
||||
* @returns {string} Domain name.
|
||||
* @returns {string} The URL of this WelcomePage for display purposes.
|
||||
*/
|
||||
_getDomain() {
|
||||
const windowLocation = window.location;
|
||||
// As the returned URL is for display purposes, do not return the
|
||||
// userinfo, query and fragment URI parts.
|
||||
const wl = window.location;
|
||||
|
||||
return `${windowLocation.protocol}//${windowLocation.host}/`;
|
||||
return `${wl.protocol}//${wl.host}${wl.pathname}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user