Reputation: 209
Have any ideas how can I get correct params ?
I getting this URL and I want navigate to correct screen within correct params.
URL -> /p-einhell-drill-screwdriver-123456/
I want to take form that url 3 parameters:
I can take all of them in one parameter but i can not spread in 3 param. At this moment I have this parser but It takes only one params.
Forxample:
const config = {
ProductScreen: {
path: ':seoName/', /* p-einhell-drill-screwdriver-123456/ */
parse: {
seoName: (seoName) =>
seoName.split('-').slice(1, -1).join('-'),
URL: (seoName) => seoName,
currentProductId: (seoName) =>
seoName.split('-').pop(),
},
},
}
Result:
params: { URL: undefined currentProductId: undefined seoName: "einhell-drill-screwdriver" }
Upvotes: 0
Views: 1374
Reputation: 10145
The options under parse
refer to the params defined in the config (e.g. :seoName
) and query params if any. You can't add arbitrary properties there.
But you can return an object in seoName
:
parse: {
seoName: URL => {
const seoName = URL.split('-').slice(1, -1).join('-');
const currentProductId = URL.split('-').pop();
return { URL, seoName, currentProductId };
}
}
And then get this object in route.params.seoName
in your component.
Upvotes: 1