Conditional route params to paths in F7 core?

How do i pass conditional route params to paths in F7 core?

Tried /?param_name but get then following error in console
0:4876 Uncaught TypeError: Unexpected MODIFIER at 1, expected END

  • at d (0:4876)*
  • at parse (0:4935)*
  • at stringToRegexp (0:5047)*
  • at pathToRegexp (0:5120)*
  • at 0:8720*
  • at Array.forEach ()*
  • at 0:8718*
  • at Array.forEach ()*
  • at t.findMatchingRoute (0:8703)*
  • at t.init (0:9229)*

Use async route property: https://framework7.io/docs/routes.html#async-route

Okay, but I’m not checking login stats of user before rendering page.

What am looking for is to show page whether parameters has being passed to URL/paths or not.

For instance, if I have my home page path defined as /, and i include a param, I want to be able to show the home page irrespective of passed param set or not.

Okay, so you want to make route query string optional.

By default, the query string (?param1=value1&param2=value2) parameters are optional in Framework7 routes.

Whether you append the query string or not, the page will always open.

Example:

<a href="/home">Home</a>
<a href="/home?q=abc">Home</a>

It will always open the /home route, regardless of the passed parameters.

1 Like

Can you please show your code, how you are accessing the route?

I think i’v gotten it now.

its file_name/:param_name?

(?) - Make the param_name optional in this sense

Yes, to make the route parameter optional, you will need to append (?) at the end of the param,

Example:

{
    path: '/home/:param1?'
}

So,

{
    path: '/home'
}

and

{
    path: '/home/:param1?'
}

are treated as same.

PS: Framework7 Router uses https://github.com/pillarjs/path-to-regexp library for route path matching. So all the functionalities of this library are supported in Framework7 as well.

1 Like

Yes sure. Thanks buddy.

1 Like