Skip to content

Commit f324d41

Browse files
committed
improved router optional parameter documentation
1 parent 523a69a commit f324d41

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

docs/plugins/router/navigation.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ This results in: `#player/12/44`
9898

9999
## Optional router path
100100

101-
You can also specify the optional router path parameter to the Router path.
102-
This is an advantage as we need not specify two different routes to the same component, instead we can specify optional field in router path with a '?' suffix for the optional params.
101+
There might be some cases in which you need a route path with an optional parameter at the end. Normally, you would have to define two different routes to the same component, one with the optional parameter and one without. Starting with Lightning-SDK `v5.3.0`, you can specify an optional router path parameter by adding a `?` suffix to the last parameter name.
103102

103+
Please note that only the last parameter of any path is allowed to be an optional parameter. For example, if you have a route path with three parameters, you can make only the last parameter optional, but not the second parameter.
104+
105+
When we define an optional parameter like this:
104106
```js
105107
{
106108
path: 'player/:assetId/:playlistId?',
@@ -109,26 +111,29 @@ This is an advantage as we need not specify two different routes to the same com
109111
}
110112
```
111113

112-
This will generate two paths as below:
114+
This will generate two paths internally as below:
113115

114116
```js
115117
{
116118
path: 'player/:assetId/:playlistId'
117119
component: Player
118120
name: 'player'
119121
}
120-
```
121-
```js
122122
{
123-
path: 'player/:assetId/',
123+
path: 'player/:assetId',
124124
component: Player,
125125
name: 'player'
126126
}
127127
```
128128

129-
Note: This will not work if the optional parameter ? is in the middle of the path. For Ex :
129+
The following example would *not* work because only the last parameter of the path can be optional:
130+
130131
```js
131-
path: 'player/:assetId?/:playlistId'
132+
{
133+
path: 'player/:assetId?/:playlistId',
134+
component: Player
135+
name: 'player'
136+
}
132137
```
133138

134139

0 commit comments

Comments
 (0)