Closed plemarquand closed 4 years ago
If parameter is present its value always a string and can't be undefined (CodePen):
import UniversalRouter from 'universal-router';
const router = new UniversalRouter({
path: '/user/:username?',
action: ({ params }) => JSON.stringify(params)
})
router.resolve('/user').then(console.log) // => {}
router.resolve('/user/').then(console.log) // => {}
router.resolve('/user/demo').then(console.log) // => {"username":"demo"}
i.e. { "username": undefined }
is not possible.
You're right, I should be guarding property existence on maps with hasOwnProperty
instead. Closing.
I'm submitting a ...
The interface for RouteParams is:
(https://github.com/kriasoft/universal-router/blob/master/src/UniversalRouter.ts#L39)
However its possible for route parameters to be optional:
Leading me to think the RouteParams interface should look like: