Skip to content

Commit

Permalink
Add hashroute redirect with machine listing fallthrough. (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
squidsoup authored May 29, 2020
1 parent 6fab5f7 commit 60b84f0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion legacy/src/app/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function configureMaas(
$locationProvider,
$compileProvider,
tagsInputConfigProvider,
$urlRouterProvider
$urlRouterProvider,
) {
// Disable debugInfo unless in a Jest context.
// Re-enable debugInfo in development by running
Expand Down
30 changes: 28 additions & 2 deletions legacy/src/app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,14 @@ const configureRoutes = ($stateProvider, $urlRouterProvider) => {
template: podDetailsTmpl,
controller: "PodDetailsController",
})
.state("pods", { url: prefixRoute("/pods"), redirectTo: prefixRoute("/kvm") })
.state("podDetails", { url: prefixRoute("/pod/:id"), redirectTo: prefixRoute("/kvm/:id") })
.state("pods", {
url: prefixRoute("/pods"),
redirectTo: prefixRoute("/kvm"),
})
.state("podDetails", {
url: prefixRoute("/pod/:id"),
redirectTo: prefixRoute("/kvm/:id"),
})
.state("master.rsd", {
url: prefixRoute("/rsd"),
template: podsListTmpl,
Expand Down Expand Up @@ -227,6 +233,26 @@ const configureRoutes = ($stateProvider, $urlRouterProvider) => {
template: dashboardTmpl,
controller: "DashboardController",
});

$urlRouterProvider.otherwise(($injector, $location) => {
// Redirect old hash routes to new routes
if ($location.hash()) {
window.history.pushState(
null,
null,
`${process.env.BASENAME}${
process.env.ANGULAR_BASENAME
}${$location.hash()}`
);
} else {
// fallthrough redirect machine listing
window.history.pushState(
null,
null,
`${process.env.BASENAME}${process.env.REACT_BASENAME}/machines`
);
}
});
};

export default configureRoutes;
6 changes: 5 additions & 1 deletion legacy/src/app/services/tests/test_region.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import MockWebSocket from "testing/websocket";

describe("RegionConnection", function() {
// Load the MAAS module to test.
beforeEach(angular.mock.module("MAAS"));
beforeEach(
angular.mock.module("MAAS", ($urlRouterProvider) =>
$urlRouterProvider.deferIntercept()
)
);

// Grab the needed angular pieces.
var $timeout, $rootScope, $q, $cookies, $window;
Expand Down
5 changes: 4 additions & 1 deletion root/src/root-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ registerApplication({
showLoading();
return import("@maas-ui/maas-ui-legacy");
},
activeWhen: `${process.env.BASENAME}${process.env.ANGULAR_BASENAME}`,
activeWhen: (location) =>
location.pathname.startsWith(
`${process.env.BASENAME}${process.env.ANGULAR_BASENAME}`
) || location.hash.startsWith("#"),
});

registerApplication({
Expand Down

0 comments on commit 60b84f0

Please sign in to comment.