Add parameter to the page url in user interface app

i want to make a dynamic url for my application in /users

    New-UDListItem -Label 'Home' -Icon (New-UDIcon -Icon Home) -OnClick {
        Invoke-UDRedirect -Url "/home"
    }
    New-UDListItem -Label 'Users' -Icon (New-UDIcon -Icon User) -OnClick {
        Invoke-UDRedirect -Url "/users"
    }
    New-UDListItem -Label 'Groups' -Icon (New-UDIcon -Icon Users) -OnClick {
        Invoke-UDRedirect -Url '/groups'
    }
)

New-UDApp -Title 'PowerShell Universal' -Pages @(
    Get-UDPage -Name 'home' 
    Get-UDPage -Name 'users'
    Get-UDPage -Name 'groups'
) -Navigation $Navigation

how can i add /users/:email to be dynamic and how can i access this param in the page?
$id = $PSBoundParameters.id this throws error

Per this doc, it seems you simply define the page with the variable URL as its URL and use the variable with traditional syntax. In your example, the URL would be /users/:email and you would access the variable in the code for that page with $Email.

Hope this helps!
:wavy_dash:ZG

i made it like this:

New-UDListItem -Label ‘Users’ -Icon (New-UDIcon -Icon User) -OnClick {
Invoke-UDRedirect -Url “/users/:id”
}

but i got this:

i tried to do:

$Pages = @()
$Pages += New-UDPage -Name 'Dashboard' -Url '/db/:id' -Content {
    New-UDTypography -Text 'Dashboard for user: $id'
}New-UDApp -Title 'Pages' -Pages $Pages
and worked but on the invoke-udridirect didnt work,
is there a way to make it work with the template u provide?

This section would need the URL to be the $ID variable I believe, rather than the URL variable syntax of :id - can you test that? I may be wrong.

With SAML2 authentication, the user’s email is passed as their identity (assuming you have upn or email as the primary identifying claim attribute), so using the following worked for me:

$Navigation = @(
        New-UDListItem -Label 'Home' -Icon (New-UDIcon -Icon Home) -OnClick {
        Invoke-UDRedirect -Url "/home"
    }
    New-UDListItem -Label 'Users' -Icon (New-UDIcon -Icon User) -OnClick {
        Invoke-UDRedirect -Url "/users/$User"
    }
    New-UDListItem -Label 'Groups' -Icon (New-UDIcon -Icon Users) -OnClick {
        Invoke-UDRedirect -Url '/groups'
    }
)

New-UDApp -Title 'PowerShell Universal' -Pages @(
    Get-UDPage -Name 'home'
    Get-UDPage -Name 'users'
    Get-UDPage -Name 'groups'
) -Navigation $Navigation

The question, I suppose, becomes how you want to define the $id parameter. The initial error is because you are creating a page at /users/:id, but no page at /users/. If you were to create a separate user page, you could then theoretically have a screen that would ask for user input for the user’s email to redirect them to.

I hope that makes sense!

1 Like

Success!

thank you

Happy to help! If you’d mark it as a solution so future users can jump to it easily that would be great!