-
-
Notifications
You must be signed in to change notification settings - Fork 344
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adds redirect for 404 how tos #1225
Merged
chrismclarke
merged 4 commits into
ONEARMY:master
from
thisislawatts:feat/adds-redirect-for-404-how-tos
Oct 7, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b098674
feat: adds redirect for 404 how tos
thisislawatts 68f39e4
feat: adds a helpful heading message for the viewer
thisislawatts 2b3ca93
fix: unload state based on URL location
thisislawatts ab03241
test: update to align with implementation
thisislawatts File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import * as React from 'react' | ||
import { RouteComponentProps } from 'react-router' | ||
import { RouteComponentProps, Redirect } from 'react-router' | ||
// TODO add loader (and remove this material-ui dep) | ||
import { inject, observer } from 'mobx-react' | ||
import { HowtoStore } from 'src/stores/Howto/howto.store' | ||
|
@@ -19,8 +19,6 @@ import WhiteBubble3 from 'src/assets/images/white-bubble_3.svg' | |
import { Link } from 'src/components/Links' | ||
import { zIndex } from 'src/themes/styled.theme' | ||
import { Loader } from 'src/components/Loader' | ||
import { Route } from 'react-router-dom' | ||
import { NotFoundPage } from '../../../NotFound/NotFound' | ||
import { UserStore } from 'src/stores/User/user.store' | ||
import { HowToComments } from './HowToComments/HowToComments' | ||
// The parent container injects router props along with a custom slug parameter (RouteComponentProps<IRouterCustomParams>). | ||
|
@@ -122,6 +120,7 @@ export class Howto extends React.Component< | |
const { isLoading } = this.state | ||
const loggedInUser = this.injected.userStore.activeUser | ||
const { activeHowto } = this.store | ||
|
||
if (activeHowto) { | ||
return ( | ||
<> | ||
|
@@ -158,7 +157,19 @@ export class Howto extends React.Component< | |
</> | ||
) | ||
} else { | ||
return isLoading ? <Loader /> : <Route component={NotFoundPage} /> | ||
return isLoading ? ( | ||
<Loader /> | ||
) : ( | ||
<Redirect | ||
to={{ | ||
pathname: '/how-to', | ||
search: | ||
'?search=' + | ||
(this.props?.match?.params?.slug).replace(/\-/gi, ' ') + | ||
'&source=how-to-not-found', | ||
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tested this out and really like the functionality, nice idea to also replace the dashes and make it look more human-readable |
||
/> | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
馃 Perhaps unneccessary as I think the datastore is completely reset between test runs so there are unlikely to be any collisions due to leaky state between test runs.
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.
It should do (cypress by default clears localstorage and we have manual methods to clear indexeddb), we also use a custom prefix in case of tests running in parallel. That being said, no real harm to include