-
Notifications
You must be signed in to change notification settings - Fork 174
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
Improve 404 handling #310
Improve 404 handling #310
Conversation
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.
One additional bug that I found during the review - when going to 'partially wrong link' from the browsers address bar (not using Luigi client), the frame is loaded twice. I think it works the same way on master, so it's not your implementations fault, although maybe it would be good to fix it within this task.
core/src/services/routing.js
Outdated
@@ -264,3 +270,24 @@ export const handleRouteClick = node => { | |||
navigateTo(route); | |||
} | |||
}; | |||
|
|||
const ShowNotExactRouteError = async ( |
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.
All variables start with lowercase letter, so could you please rename it to showNotExactRouteError
to consistency?
core/src/services/routing.js
Outdated
} | ||
//the path is unrecognized at all and cannot be fitted to any known one | ||
const custom404handler = LuigiConfig.getConfigValue( | ||
'settings.handle404' |
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.
I would rename handle404
since all functions in our config are nouns. 404handler
or something like that.
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.
And I think that 404 handler should be part of navigation, not settings?
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.
404handler
was the first name I thought about but variable names can't start with number.
I decided to place it in settings because, in my opinion, it's not related to navigation. Any other suggestions about the name? I've got no idea what I should change it to :D
core/src/services/routing.js
Outdated
|
||
component.set({ alert }); | ||
navigateTo('/'); | ||
if (defaultChildNode && pathData.navigationPath.length > 2) { |
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.
What is this pathData.navigationPath.length > 2
for?
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.
- In case (probably impossible)
pathData.navitationPath
was empty, there will be no errors. - I've just changed it to
1
becauseoverview
is a defaultChild for/
. If it was set to >0 or not present at all, "Could not find exact route" error would appear instead of "Could not find requested route" due to automatic redirection to/
.
Thanks for noticing 2
was the wrong number 👍
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.
I would rather create a variable out of pathData.navigationPath.length > 1
to make clear what we are checking here through the variable name.
|
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.
Check the comments please.
core/src/App.html
Outdated
|
||
window.addEventListener('popstate', async e => { | ||
const alert = this.get().alert; | ||
if (alert && alert.ttl !== undefined) { |
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.
I would use typeof number
here, just to be save.
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.
I'd love to use isInteger()
but Internet Explorer's compatibility blocks me from doing this :(
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.
Right now it doesn't work for 'partially wrong link'
@@ -320,6 +320,11 @@ var projectsNavProviderFn = function(context) { | |||
}); | |||
}; | |||
|
|||
var customPageNotFoundHandler = function(wrongPath, wasAnyPathFitted) { |
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.
Maybe it would be good to add to documentation that this function might receive wrongPath
and wasAnyPathFitted
?
core/src/services/routing.js
Outdated
: 'Could not find the requested route', | ||
link: notFoundPath, | ||
ttl: pathToRedirect === '/' ? 2 : 1 //how many redirections the alert will 'survive'. | ||
//Redirecting to '/' causes another redirection to '/overview', that's why TTL needs to be bigger |
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.
In our case it's ok, because we don't have a view for '/', so it redirects to '/overview', but what if someone has a view on '/' and doesn't have this additional redirection?
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.
🤔
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.
Minor comments
Co-Authored-By: parostatkiem <[email protected]>
Co-Authored-By: parostatkiem <[email protected]>
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.
LGTM
Improve 404 handling
Description
lerna bootstrap
required!Changes proposed in this pull request:
ttl
property which lets it survive n redirects (set to 1)Could not map the exact target...
error appears when user tries to enter a route with a defaultChildNode at the end and he's redirected to that node.extendedConfiguration.js::583
to be able to see it)Related issue(s)
Resolves #310, #281