使用total.js进行漂亮的路由(比如'base_url / @ username')

时间:2022-10-22 13:39:56

I'm new to node.js, have been using Ruby and RoR.

我是node.js的新手,一直在使用Ruby和RoR。

I'd like to show a view for user view with a pretty routing.

我想用漂亮的路由显示用户视图的视图。

In Rails, I can handle with code like this:

在Rails中,我可以使用这样的代码处理:

get '@:username' => 'users#show'

So I tried in Total.js as same, but error appeaerd with 404: Not found:

所以我在Total.js中尝试了相同,但错误上传了404:未找到:

exports.install = function() {
  F.route('/@{username}', view_user);
}

How can I get my user view with localhost:8000/@my_name in total.js?

如何在total.js中使用localhost:8000 / @ my_name获取用户视图?

1 个解决方案

#1


You must remove @ from the route:

您必须从路线中删除@:

exports.install = function() {
    F.route('/{username}/', view_user);
};

function view_user(username) {
    if (!username.startsWith('@')) {
        this.throw404();
    else
        this.plain(username);
});

Thanks.

#1


You must remove @ from the route:

您必须从路线中删除@:

exports.install = function() {
    F.route('/{username}/', view_user);
};

function view_user(username) {
    if (!username.startsWith('@')) {
        this.throw404();
    else
        this.plain(username);
});

Thanks.