-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[BC Break] Add support mounting admin inside a sub path #7100
Conversation
import { useInRouterContext } from 'react-router-dom'; | ||
import { History } from 'history'; | ||
|
||
import { HistoryRouter } from './HistoryRouter'; |
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 upgraded react-router to 6.1 to get their new HistoryRouter, but they've made in "unstable" in v6.1.1, so we still need to use our own.
@@ -38,8 +38,8 @@ | |||
"react-dom": "^17.0.0", | |||
"react-final-form": "^6.5.7", | |||
"react-redux": "^7.1.0", | |||
"react-router": "^6.0.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.
This change is not necessary - I wanted their HistoryRouter but the've hidden it behind an "unstable" flag.
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.
As previously mentionned, there's v6.2.1 now: https://github.com/remix-run/react-router/releases
@@ -476,16 +476,16 @@ And now you can use a regular Field component, and the label displays correctly | |||
|
|||
### Linking To Other Records | |||
|
|||
A custom Field component might need to display a link to another record. React Admin provides a `linkToRecord(basePath, id[, linkType])` method for this purpose. | |||
A custom Field component might need to display a link to another record. Build the URL to the distant record using the resource name and the id, as follows: |
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.
Probably a good time to introduce useCreateInternalLink
@@ -3,11 +3,9 @@ import FieldTitle, { FieldTitleProps } from './FieldTitle'; | |||
import getFetchedAt from './getFetchedAt'; | |||
import getFieldLabelTranslationArgs from './getFieldLabelTranslationArgs'; | |||
import ComponentPropType from './ComponentPropType'; | |||
import linkToRecord from './linkToRecord'; |
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.
moved to the routing directory
@@ -1,11 +0,0 @@ | |||
import * as React from 'react'; |
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.
useless component: LoadingPage is already set as default prop in AdminUI
Looks great. I was setting up my own Is Should the docs provide advice to switch away from |
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.
Neat! This is so much better 💪
"react-router": "^6.1.0", | ||
"react-router-dom": "^6.1.0", |
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.
"react-router": "^6.1.0", | ||
"react-router-dom": "^6.1.0", |
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.
"react-router": "^6.1.0", | ||
"react-router-dom": "^6.1.0" |
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.
@@ -38,8 +38,8 @@ | |||
"react-dom": "^17.0.0", | |||
"react-final-form": "^6.5.7", | |||
"react-redux": "^7.1.0", | |||
"react-router": "^6.0.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.
As previously mentionned, there's v6.2.1 now: https://github.com/remix-run/react-router/releases
/** | ||
* @deprecated use useCreatePath instead | ||
*/ | ||
export const linkToRecord = (resource, id, linkType = 'edit') => { | ||
const link = `${resource}/${encodeURIComponent(id)}`; | ||
|
||
if (linkType === 'show') { | ||
return `${link}/show`; | ||
} | ||
|
||
return link; | ||
}; |
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.
Should be deprecated in next v3 and removed here
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.
We don't need to remove it here - it would force an even longer upgrade.
It's just not used anymore, and doesn't do any harm until v5.
import { To } from 'react-router-dom'; | ||
|
||
/** | ||
* @deprecated use useCreatePath instead |
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.
Same
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.
Same answer: we don't remove it to avoid a more painful upgrade.
"react-router": "^6.1.0", | ||
"react-router-dom": "^6.1.0", |
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.
Same, more recent version available
"react-router": "^6.1.0", | ||
"react-router-dom": "^6.1.0", |
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 too
"react-router": "^6.1.0", | ||
"react-router-dom": "^6.1.0", |
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.
Again
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.
Impressive work!
I couldn't been able to find problems 💪
@djhi Let's upgrade the packages to their latest version in another PR (and rather at the end of the 4.0 roadmap), to avoid multiple rebases due to yarn.lock conflicts. |
No, Should the docs provide advice to switch away from HashRouter? I totally understand it being the default to facilitate getting started quickly, but e.g. react-router docs say "We strongly recommend you do not use HashRouter unless you absolutely have to.".
|
Problems
React-router v6 doesn't support nesting routers. So it will break for users who use react-router to mount the admin in a sub path (e.g. "admin").
The way react-admin v3 used to support sub path relied on passing the
basePath
everywhere, which is not very good DX.We need to reintroduce the ability to mount react-admin in a sub path, without using
basePath
.Use case
Solution
basePath
prop everywhere