fune/browser/components/asrouter/content-src/components/ASRouterAdmin/SimpleHashRouter.jsx
Mike Conley 9415a9f13d Bug 1866802 - Move ASRouterAdmin tool to about:asrouter and its own component folder. r=pdahiya,Gijs,desktop-theme-reviewers,dao
This tries to maintain stylistic continuity, while also trying to decouple from
newtab as much as possible. This is a first foray, and future patches will
further this decoupling.

This also modifies about:asrouter to show an error message if the ASRouter devtools
pref is not set to true.

Differential Revision: https://phabricator.services.mozilla.com/D194811
2023-12-14 18:46:55 +00:00

35 lines
915 B
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
import React from "react";
export class SimpleHashRouter extends React.PureComponent {
constructor(props) {
super(props);
this.onHashChange = this.onHashChange.bind(this);
this.state = { hash: global.location.hash };
}
onHashChange() {
this.setState({ hash: global.location.hash });
}
componentWillMount() {
global.addEventListener("hashchange", this.onHashChange);
}
componentWillUnmount() {
global.removeEventListener("hashchange", this.onHashChange);
}
render() {
const [, ...routes] = this.state.hash.split("-");
return React.cloneElement(this.props.children, {
location: {
hash: this.state.hash,
routes,
},
});
}
}