hongfu
December 28, 2018, 4:10am
1
Something is wrong if you used the property alias for routs defining.
When i defined routes like this:
{
path: '/t/',
alias: [
'/t1/:t1',
'/t2/:t2'
],
componentUrl: './t.html',
name: 'test'
}
and made links in page.
<a href="/t1/111">test1</a>
<a href="/t2/222">test2</a>
If i click ‘test1’ ,there is no problem: params just is one object was passed as
[t1:‘222’]
But when i click ‘test2’
What’s happened?
There are two objects in one collection passed
[t1:222,t2:undefined]
hongfu
December 28, 2018, 4:49am
2
Is there any better way be solution without changing routes to a huge objects collection?
What is the point of this? You can just have single route with optional parameters by adding ?
to the end of it:
path: '/t/:foo?'
hongfu
December 29, 2018, 12:33am
4
The key is:
If you want to pass parameters through router components,
Errors may occur when routing tables use the optional parameter “alias”.
I defined routes as
var routes = [
path: '/some-page/',
alias: [
'/some-page1/:param1/',
'/some-page2/:param2/',
'/some-page3/:param3/'
],
componentUrl: './some-page.html',
];
I want to go some-page with passing parameter as
{ param3:‘passed3’ }
click on the link as
<a href="/some-page3/passed3/">button</a>
The unwanted parameter was passed through route.params
{ param1:‘passed3’,param2:undefined,param3:undefined }
Ok, will check it. Maybe an issue somewhere. But it is still better to add different route. You can do it with func to avoid a lot of extra code:
function somePageRoute(path) {
return {
path: path,
componentUrl: './some-page.html',
}
}
var routes = [
somePageRoute('/some-page/'),
somePageRoute('/some-page1/:param1/'),
somePageRoute('/some-page2/:param2/'),
somePageRoute('/some-page3/:param3/'),
];
hongfu
December 30, 2018, 2:52am
6
Thx for helping!
Be better,
Because i want to get diff obj via route.params at same page from diff path.
It works!