I wonder how to make 1 state with 2 urls options: /dashboard & /dashboard/verification/:verificationToken
Thats my state code:
.state('app.dashboard', {
url: '/dashboard',
controller: 'DashboardController',
templateUrl: 'src/components/app/dashboard/dashboard.html'
})
I know the simplest solution is to make 2 states: app.dashboard & app.dashboardWithVerification, but I think it's wrong way.
.state('app.dashboard', {
url: '/dashboard',
controller: 'DashboardController',
templateUrl: 'src/components/app/dashboard/dashboard.html'
})
.state('app.dashboardWithVerification', {
url: '/dashboard/verification/:verificationCode',
controller: 'DashboardController',
templateUrl: 'src/components/app/dashboard/dashboard.html'
})
Any idea? Thanks.
How about having a single state dashboard with an optional param :verificationCode? When the verificationCode state param is empty, the url will fallback to something like /dashboard. Else it will be /dashboard/<some code here>. For this you also need to define default param values in your state config :
.state('app.dashboard', {
url: '/dashboard/:verificationCode',
controller: 'DashboardController',
templateUrl: 'src/components/app/dashboard/dashboard.html',
params : {
verificationCode : ''
}
});
For transition you can do either $state.go('dashboard') or $state.go('dashboard',{verificationCode : 'abcxyz'}).
I am not sure if this is the best way to achieve something like this in UI Router. I have not done Angular for a year now. Looking forward to seeing what others suggest.
I like the idea of using 2 states, here's my thinking...
UI-Router calls them "states" instead of some other name because they do in fact represent different states of your application. I'd say that "being at the dashboard" and "being at the dashboard with verification" are 2 different states, even if they render the same HTML page.
Dave Ceddia
Javascript developer
I like the idea of using 2 states, here's my thinking...
UI-Router calls them "states" instead of some other name because they do in fact represent different states of your application. I'd say that "being at the dashboard" and "being at the dashboard with verification" are 2 different states, even if they render the same HTML page.