-
-
Notifications
You must be signed in to change notification settings - Fork 916
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
Read params from html route structure, pass via props #774
Comments
I agree this would be nice. This would best be implemented in single-spa, not single-spa-layout, since parsing the route paths and providing props to single-spa applications is done within single-spa. Going to transfer this issue over to single-spa for that reason. The url paths are converted to regular expressions via single-spa's pathToActiveWhen function. That function converts the string to a regular expression, but doesn't capture the params in a regex capture group. So the first step is to get the regex to capture the params (see this code). Maybe the best implementation would be to have the application's activity function return an object of url parameters, since it's the activity function that has access to that regex. So instead of calling |
Would it be an idea to provide this information via the routing-events that are dispatched by single-spa as well @joeldenning? I have a use case where it would be practical to get an object with the params of the current route from the |
I'd be open to adding it to the routing event detail objects. If it's implemented as I suggested above, I think this would be possible since we call the activity functions inside of reroute, which is also where we fire the routing events. |
Is anyone already working on the implementation? I would like to contribute to this ticket if no one has started working on it. |
I don't think so. I was keen on taking this issue, but i haven't had time to properly get into it. It would be awesome if you did, because i have some real use cases for this feature! @dsfx3d |
I have not worked on this - feel free to do so @dsfx3d! |
Ok guys I'll look into it. Thanks |
@joeldenning we'll have to make the object reactive so that the params stay in sync with the URL in the browser. Is there already some functionality built for reactivity? or we can build something like that from scratch |
Hmm that's a good point I hadn't considered, the dynamic portions of route params would need to be updated as navigation occurs, but the application may not go through a mount/unmount lifecycle when that happens. We could try passing a route params object as props that uses a javascript property getter to dynamically calculate the route params. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get |
@joeldenning I think there's one more scenario to consider at this point. I understand that we pass props from single-spa and can use |
single-spa/src/applications/apps.js Line 431 in f67d6fc
|
yes but my concern is if there's a way to determine if we are using history mode or hash mode. |
got it I was also considering including URL query as an object in props along with params. |
You can tell whether the url path is history mode or hash mode based on whether the path given to single-spa contains a |
@joeldenning First of all, thank you for this great framework. I use it a lot and really start to love it! |
Hi Ebbele, great if you've made progress on this issue! We'd encourage you to submit a PR and reference this issue in it, and then we know that someone is still working on it. In other news, is anyone still finding this is important to them? Or is everyone just doing their own parameter parsing and that's fine? |
We have also figured out our own parameter parsing but it would be nice if it was done for us. |
@joeldenning I created a PR. I'm surprised this issue is still open. Please review if this is the correct approach. |
It would be really nice and intuitive if single-spa passed down the params from the url (like
/settings/:userId/profile
resulting a{ userId: 123 }
object).This is fairly common among routers, vue-router uses path-to-regexp which looks like a promising package to apply to single-spa-layout as well.
How would we go about doing this?
The text was updated successfully, but these errors were encountered: