Next-routes: Expected value to be a string

Created on 12 Mar 2018  路  2Comments  路  Source: fridays/next-routes

next routes sequence like :
routes.add({
name: 'index',
pattern: '/',
page: 'index'
});
routes.add({
name: 'users',
pattern: '/:user',
page: 'users'
});

sometimes I get the error when I enter the index error message: Expected "user" to be a string
error path to regexp module
throw new TypeError('Expected "' + token.name + '" to be ' + (token.repeat ? 'an array' : 'a string')

Error section in next routes:
key: 'getAs',
value: function getAs() {
var _this5 = this;

var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

var as = this.toPath(params) || '/';
var keys = Object.keys(params);
var qsKeys = keys.filter(function (key) {
return _this5.keyNames.indexOf(key) === -1;
});

Most helpful comment

I had a similar error with that route:

routes.add('office', '/(office|cabinet)/:office');

I had to change from
<Link route="office" params={{ office: 'robert' }}>
to
<Link route="office" params={{ office: 'robert', 0: 'cabinet' }}>

Thanks for the tip fridays!

All 2 comments

The message would make sense if you linked to route='users' without a user param. If it's happening elsewhere please provide some steps to reproduce

I had a similar error with that route:

routes.add('office', '/(office|cabinet)/:office');

I had to change from
<Link route="office" params={{ office: 'robert' }}>
to
<Link route="office" params={{ office: 'robert', 0: 'cabinet' }}>

Thanks for the tip fridays!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adekbadek picture adekbadek  路  4Comments

arefaslani picture arefaslani  路  3Comments

joncursi picture joncursi  路  3Comments

haotangio picture haotangio  路  5Comments

ccuilla picture ccuilla  路  6Comments