Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

app state with optional param and no trailing slash

.state('tabs.map', {
    url:'/map/{location_id}',
    params: {
      location_id: { value: -1 }
    },
    views: {
      'map-tab':{
        templateUrl:'templates/map.html',
        controller:'MapCtrl'
      }
    }
  })

I've tried a number of different options for optional params that I've found on the web but none of them work exactly like I'm looking for. The code I've added allows for:

  • /tab/map/.*?

  • /tab/map/

but not

  • /tab/map

I'm not sure why the trailing slash is causing a problem because from what I've read it shouldn't be a problem. Does anyone know how to resolve this?

Recently Consulted

  • Angular UI-Router: Multiple URLs to single state
  • AngularJs UI router - one state with multiple URLs
  • Can angularjs routes have optional parameter values?
  • Laravel 4 Route issues with multiple and optional get params

Solution

Introduction of squash to param variable

.state('tabs.map', {
    url:'/map/:location_id',
    params: {
      location_id: { value:null, squash:true }
    },
    views: {
      'map-tab':{
        templateUrl:'templates/map.html',
        controller:'MapCtrl'
      }
    }
  })
like image 962
Jacksonkr Avatar asked May 21 '15 15:05

Jacksonkr


People also ask

What URLs should not have a trailing slash?

A trailing slash should not be added for URLs that end in a file name, such as .html, .php, .aspx, .txt, .pdf or .jpg. If you force a trailing slash on a file name, then that will cause the browser to think it is a folder and will result in a 404 error message.

Do trailing slashes matter in Google search?

Google sees the two as equivalent. But trailing slashes do matter for everything else because Google sees the two versions (one with a trailing slash and one without) as being different URLs. Conventionally, a trailing slash (/) at the end of a URL meant that the URL was a folder or directory.

What does the slash at the end of a URL mean?

The trailing slash matters for most URLs Conventionally, a trailing slash (/) at the end of a URL meant that the URL was a folder or directory. At the same time, a URL without a trailing slash at the end used to mean that the URL was a file. However, this isn’t how many websites are structured today.

Is it better to have a trailing slash or trailing slash?

There is certainly no SEO benefit to switching. On the other hand, if you are starting a new site today, then it is probably better to include a trailing slash simply because this is more common and more likely to be expected by users. Whichever one you choose, it makes sense to be ultra-consistent and have 301 redirects from one to the other.


1 Answers

You can use squash parameter to allow without trailing slash

  params: {
      location_id: {
        value: null,
        squash: true
      }
   }
like image 114
kwangsa Avatar answered Nov 15 '22 06:11

kwangsa