mirror of
https://github.com/getredash/redash.git
synced 2026-05-13 16:01:20 -04:00
Handle unknown routes in Angular by showing Page Not Found error
This commit is contained in:
@@ -44,17 +44,21 @@ class AppViewComponent {
|
||||
$rootScope.$on('$routeChangeStart', (event, route) => {
|
||||
this.handler.reset();
|
||||
|
||||
if (route.$$route.authenticated) {
|
||||
// In case we're handling $routeProvider.otherwise call, there will be no
|
||||
// $$route.
|
||||
const $$route = route.$$route || { authenticated: true };
|
||||
|
||||
if ($$route.authenticated) {
|
||||
// For routes that need authentication, check if session is already
|
||||
// loaded, and load it if not.
|
||||
logger('Requested authenticated route: ', route);
|
||||
if (Auth.isAuthenticated()) {
|
||||
this.applyLayout(route.$$route);
|
||||
this.applyLayout($$route);
|
||||
} else {
|
||||
event.preventDefault();
|
||||
// Auth.requireSession resolves only if session loaded
|
||||
Auth.requireSession().then(() => {
|
||||
this.applyLayout(route.$$route);
|
||||
this.applyLayout($$route);
|
||||
$route.reload();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -103,6 +103,18 @@ function registerPages() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
ngModule.config(($routeProvider) => {
|
||||
$routeProvider.otherwise({
|
||||
resolve: {
|
||||
// Ugly hack to show 404 when hitting an unknown route.
|
||||
error: () => {
|
||||
const error = { status: 404 };
|
||||
throw error;
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function registerFilters() {
|
||||
|
||||
Reference in New Issue
Block a user