diff --git a/imports/api/Common/id.js b/imports/api/Common/id.js new file mode 100644 index 0000000..d419982 --- /dev/null +++ b/imports/api/Common/id.js @@ -0,0 +1,15 @@ +/* + * Fire/collection docs use `idGeneration: 'MONGO'`, so their `_id` is a + * `Mongo.ObjectID`, whose `.toString()` yields `ObjectID("")` — NOT the + * bare hex. Interpolating an `_id` straight into a URL or any string therefore + * produces `.../fire/archive/ObjectID("...")`, which the routes can't match. + * + * Use `hexId()` wherever an id becomes part of a string (URLs, comment + * reference ids, DOM ids). It returns the 24-char hex for an ObjectID and + * passes plain-string ids through unchanged. Do NOT use it for DDP method + * args whose `check()` expects `Meteor.Collection.ObjectID` — pass the object. + */ +export const hexId = id => + (id && typeof id.toHexString === 'function' ? id.toHexString() : id); + +export default hexId; diff --git a/imports/ui/components/Maps/MarkListeners.js b/imports/ui/components/Maps/MarkListeners.js index 5a85b44..19ffc39 100644 --- a/imports/ui/components/Maps/MarkListeners.js +++ b/imports/ui/components/Maps/MarkListeners.js @@ -1,4 +1,7 @@ +import { hexId } from '/imports/api/Common/id'; + export const onMarkClick = (history, nasa, id) => { // console.log('onClick fired'); - history.push(`/fire/${nasa ? 'active' : 'alert'}/${id}`); + // hexId: `id` is a Mongo.ObjectID whose toString() is `ObjectID("...")`. + history.push(`/fire/${nasa ? 'active' : 'alert'}/${hexId(id)}`); }; diff --git a/imports/ui/pages/Fires/Fires.js b/imports/ui/pages/Fires/Fires.js index 4c79cf5..7790aeb 100644 --- a/imports/ui/pages/Fires/Fires.js +++ b/imports/ui/pages/Fires/Fires.js @@ -18,6 +18,7 @@ import FiresCollection from '/imports/api/Fires/Fires'; import FireList from '/imports/ui/components/Maps/FireList'; import FromNow from '/imports/ui/components/FromNow/FromNow'; import { dateLongFormat, dateYYYYMMDD } from '/imports/api/Common/dates'; +import { hexId } from '/imports/api/Common/id'; import CommentsBox from '/imports/ui/components/Comments/CommentsBox'; import FalsePositiveTypes from '/imports/api/FalsePositives/FalsePositiveTypes'; import FalsePositivesCollection, { falsePositivesRemap } from '/imports/api/FalsePositives/FalsePositives'; @@ -41,7 +42,7 @@ class Fire extends React.Component { // console.log(`Next when ${nextProps.when}`); if (nextProps.fire && (nextProps.alert || nextProps.active || nextProps.fromHash)) { // change url to archive with new _id - nextProps.history.replace(`/fire/archive/${nextProps.fire._id}`); + nextProps.history.replace(`/fire/archive/${hexId(nextProps.fire._id)}`); } this.setState({ loading: nextProps.loading, @@ -232,7 +233,7 @@ class Fire extends React.Component {
- +
}