Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js: trailing slash in the end of url route

Tags:

I have url routes in my app Router.js:

'items': 'items', 'items/drafts': 'itemsDrafts', 'items/drafts/new': 'itemsDraftsNew', ... 

But in browser when I define items/drafts/new/ it gives me 404 error :(

Is there a way to make this urls the same without copy-pasting all routes and adding trailing to them like:

'items': 'items', 'items/drafts': 'itemsDrafts', 'items/drafts/new': 'itemsDraftsNew', 'items/': 'items', 'items/drafts/': 'itemsDrafts', 'items/drafts/new/': 'itemsDraftsNew', ... 

?

Thanks!

like image 310
Kosmetika Avatar asked Jul 10 '13 11:07

Kosmetika


People also ask

How to remove trailing slash from URLs in react router?

This is a super quick example of how to remove trailing slashes from URLs in React apps that use React Router. The solution is to add the following react router <Redirect ... /> that matches any URL with a trailing slash and automatically redirects it to the same URL without the trailing slash.

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.

Should you add a trailing slash to your URLs?

If you decide to include the trailing slash (like I do), then you should set up a 301 redirect from the non-trailing slash version to the trailing slash version. A trailing slash should not be added for URLs that end in a file name, such as .html, .php, .aspx, .txt, .pdf or .jpg.

Do trailing slashes matter in Seo?

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.


1 Answers

my solution: 'url(/)': 'urlFunc'

() - means optional (also take a look here - https://stackoverflow.com/a/14329976/2117550)

like image 116
Kosmetika Avatar answered Nov 10 '22 06:11

Kosmetika