2016-11-11 21 views
1

请花些时间COMPLETELY读物在提问前打标或应答text url参数如何工作?

我想在URL,并使用相同的访问它来显示从数据文本。例如。

http://stackoverflow.com/questions/24888693/how-does-out-parameter-work

声明本页面是如何利用目前我使用requireJs在我的web应用程序backboneJs帕拉姆how-does-out-parameter-work

访问。所以,在我的路由器我很喜欢路由

siteTitle = 'Boiler Plate'; 

define([ 
    'jquery', 
    'underscore', 
    'backbone', 
    'handlebars', 
    'jcookie', 
    'views/home', 
    'views/404' 
], function ($, _, Backbone, Handlebars, jcookie, HomePage, FoFPage) { 
    var AppRouter = Backbone.Router.extend({ 
     routes: { 
      ':*':'home', 
      'home' : 'home', 
      'home/:a' : 'home', 
      '*whatever' : '404' 

     }, 
     home: function (a) { 
      document.title = siteTitle + ' - Home'; 
      homePage = new HomePage({route: a}); 
      homePage.render(); 
     }, 
     404: function(){ 
      document.title = siteTitle + ' - 404'; 
      fofPage = new FoFPage; 
      fofPage.render(); 
     } 

    }); 

    var initialize = function() { 
     var app_router = new AppRouter; 
     Backbone.history.start(); 

    }; 
    return { 
     initialize: initialize, 
     AppRouter: AppRouter 
    } 
}); 

请注意,我得到传递的参数a并据此加载页面。目前,我正在将该参数a设置为我的帖子ID并相应地使用它。如果我想传递我的文章标题的一部分并访问它,我该怎么做?

我能想到的一个办法是选择从MySQL数据库字符串和基于URL输入,但它不会有所帮助,如果该参数是how-does-out-parameter-work我永远不能解析它为How does 'out' (parameter) work?这是在数据库中的实际文本。我错过了什么?

UPDATE

的忽略后一个参数是只适用于stackvoerflow不得在本网站 https://www.theguardian.com/us-news/2016/nov/10/hate-crime-spike-us-donald-trump-president使用别的东西。我错过了什么?

+1

实际上'how-does-out-parameter-work'被忽略。这只是做一个漂亮的网址。实际上,您可以通过将其保留在相同的页面。 - >例如。 http://stackoverflow.com/questions/24888693 IOW:这是重要的数字部分.. – Keith

+1

我假设他们会有一个类似'us-news /:year /:month /:day /:heading'的路线,他们会有一个databse函数,像 - >'getDoc(年,月,日,标题)' – Keith

+0

@ Keith OK!那是我的问题!他们如何解析'getDoc(年,月,日,标题)'。因为如果标题中有括号或特殊字符,则不会在url中显示。 '如果参数是怎么做 - 参数工作,我永远不能解析它如何'出'(参数)的工作?这是数据库中的实际文字' – unkn0wn

回答

0

如果您试图按照与Stackoverflow相同的过程,它们似乎对每个问题都使用Id。我只能推测标题参数用于什么。

http://stackoverflow.com/questions/24888693/how-does-out-parameter-work 

等同于以下内容:

{domain}/{questions}/{questionId}/{title-string} 

你可以看到title-string是一个选项参数,如下仍会路由你正确的问题

http://stackoverflow.com/questions/24888693 

的附加参数如果问题Id计数器必须重置,可能会停止导致数据库中存在问题的重复Id。

也许你可以澄清为什么你需要在数据库中搜索超过字符串?

+0

感谢您的输入,但它未能解释'https://www.theguardian.com/us-news/2016/nov/10/feed-crime-spike-us-donald-trump-president' – unkn0wn