User defined navigation return 404 after press `F5`

NodeBB Development
  • I defined a navigation in admin console named MyView with route /myview
    0_1453360394146_Screenshot from 2016-01-21 15:11:12.png

    Bellowed is the init code in my plugin

    plugin.http = {};
    plugin.http.get = function(req, res, next) {
    	res.render('myview', {});
    };
    plugin.init = function(data, callback) {
    	data.router.get('/api/myview', plugin.http.get);
    	callback();
    };
    

    code in plugin.json

    "library": "./library.js",
    	"hooks": [
    		{
    			"hook": "static:app.load", "method": "init"
    		}
    	],
    	"staticDirs": {
    		"static": "./static"
    	},
    	"less": [
    		"static/myview.min.less"
    	],
    	"templates": "templates"
    

    the templates/myview.tpl is quite simple with static HTML 'Hello nodebb'


    Works well when access the page from navigation bar. But the title is missing, it's still 'Home'
    0_1453361080432_Screenshot from 2016-01-21 15:24:19.png

    Stay here, then press 'F5' it becames 404.
    0_1453361207705_Screenshot from 2016-01-21 15:26:39.png

    Any outstanding I should do Or I did it in a wrong way?

  • You have to define a /api/myroute and /myroute so F5 works as well. You can use the helper class from routes.

    Check this out https://github.com/NodeBB/NodeBB/blob/master/src/routes/helpers.js#L5

    Usage

    var helpers = require.main.require('./src/routes/helpers');
    plugin.init = function(data, callback) {
        helpers.setupPageRoute(data.router, '/myview', data.middleware, [], plugin.http.get);
        callback();
    };
    
    
  • @baris Chrees! This really helps. 👍


Suggested Topics


  • 0 Votes
    1 Posts
    1k Views

    Hi everyone, just set up my nodebb, and there are two problems I cannot fix on my own, It will be great if I can have some help here.

    1 > Is there any way for me to add some new attributes for the users myself? Like, forum coin, every time a new account created, attribute forum coin=0 attach to that account.

    I don't have too much experience on the web development, so my first thought was to create a new schema in the database for the user, and try to implement the new value, and make it visible on the page. But immediately I realized that the mongodb don't have a fixed schema, so apparently it is a wrong way to go to start from the database.

    2> I accidentally deleted the user uid=3, is there any way for me to regain the number, 3? I created user uid=4, and tried to update the _key and uid into 3 in mongodb, but eventually the account uid=4 just disappear from the forum altogether. I know this is kind of dangerous so never mind if it's difficult.

  • Custom Entity for User

    NodeBB Development
    0 Votes
    2 Posts
    893 Views

    Take a look at how we store users. We increment a global user id each time a new user is created and store the user data in an object with the name user:<userId> and we store the userId in a sorted set. You need to do something similar for businesses.

    Everytime a new business is created assign it a unique id and store it at business:<businessId> and then also store it for the user at uid:<uid>:businesses.

    It would look something like below in nodebb code. This is obviously pseudocode.

    incr businessId in database setObject businness:bussinessId businessData sortedSetAdd uid:<uid>:businesses Date.now() businessId

    Now you can retrieve a users business with the getSortedSetRange commands using the key uid:<uid>:businesses.

  • 0 Votes
    5 Posts
    2k Views

    @pitaj said:

    you could just add some JavaScript to parse it client side.

    That is more than likely what I'll have to do for now until this can passed globally. Thanks @pitaj

  • 0 Votes
    3 Posts
    2k Views

    Thanks, I have just solved the error.

    But the code doesn't work for now. How can I do execute a function when user go to topic?

    Thanks

  • 0 Votes
    2 Posts
    1k Views

    @trevor I think they recently implemented that when a user is deleted/banned, that their socket get closed. Or words to that effect. Don't quote me on that though.