geblanco / electron-router Goto Github PK
View Code? Open in Web Editor NEWRouter solving Electron hell callback passing, helpfull for MVC
License: MIT License
Router solving Electron hell callback passing, helpfull for MVC
License: MIT License
Electron-router how to use in the angular 2๏ผ
thanks
Hi all. In my main.js
I have defined routes look like this
router.on('ready', () => {
router.on('quit', () => {
});
router.on('register', (req, res) => {
showTemplate(APP.Templates.Register);
});
router.on('login', (req, res) => {
showTemplate(APP.Templates.Login);
});
router.on('logout', (req, res) => {
storage.delete(API.UserIDKey);
storage.delete(API.UserTokenKey);
API_USER = {};
router.send('login');
});
router.on('dashboard', (req, res) => {
console.log(1);
showTemplate(APP.Templates.Dashboard)
});
router.on('accounts', (req, res) => {
getDashboard();
});
});
Than I am checking ,if the user has logined than redirect to the dashboard route
if (typeof API_USER.token !== 'undefined' && typeof API_USER.id !== 'undefined') {
router.send('dashboard');
}
But the route sending is not working. Please help!
Hi. In my app I have a code look like this
const electron = require('electron')
var url = require('url')
var path = require('path');
const Router = require('electron-router')
let router = Router()
const {app, BrowserWindow, Menu} = electron
var mainWindow = null;
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('ready', function () {
mainWindow = new BrowserWindow({});
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, '/templates/login.html'),
protocol: 'file:',
slashes: true
}));
mainWindow.on('closed', function () {
mainWindow = null;
});
const mainManu = Menu.buildFromTemplate([])
Menu.setApplicationMenu(mainManu)
router.on('ready', () => {
console.log(11212)
router.on('quit', () => {
})
})
});
router.get('registration', (req, res) => {
console.log(1111)
})
And in my login.html
I have a a
tag
<a href="registration" class="nav-link">Registration</a>
So after clicking on a
console.log()
, also now torking ready
event of router
hi fiends !!
I got this error when I used axios with the electron in Main Process to fetch data from electron .
Error: Timeout - 200ms elapsed at eval
first of all thanks for the great module. I am using it in a multi-threaded (multi-window, but only the main window is visible) application which gathers information from various channels (IP, CAN-bus, etc.) and displays it in the UI.
When I test an object (using jest) which creates a router, Router(name) fails with the following error:
at Router._isRenderProcess (node_modules/electron-router/router.js:153:20)
at Router._setup (node_modules/electron-router/router.js:117:18)
at Router (node_modules/electron-router/router.js:110:12)
at node_modules/electron-router/router.js:440:17
at new ChangeHandler (src/common/changeHandler.ts:22:20)
at Object.it (__tests__/changeHandler.test.js:21:20)
it seems you access the remote
object, which is not available in the JEST environment (since electron is not running). is there a way around this?
Hi,
thanks for project
Today, i have a error :
"Uncaught TypeError: Cannot read property 'hasOwnProperty' of undefined", source: D:\Dropbox\Skyhotel_Int_Apps\electron_tong_dai_tulip123\electron\node_modules\electron-router\router.js (168)
and at line router.js (168)
return remote.hasOwnProperty('getCurrentWindow')
Can you fix this error ?
Hi, very good module !
Can you please when you planed Template rendering (i.e.: res.render(data)) ?
Thank you in advance.
Best Regards, Julien
Need a simple complete working example.
This routing library is tiny, and seems promising,
The documentation also seems to be good, however, one thing missing is a simple but complete working example. Without that, I'm afraid to send a few hours trying to get this to work by trial and error.
If a window is closed, Router.prototype.clean
is run in response to the window's close
event:
https://github.com/m0n0l0c0/electron-router/blob/db1f1fa487bc98552eaa47a18e562fd4e92cc365/router.js#L116-L123
However, this.clean
is not bound to this
, so trying to access members of the _name
property will fail with a TypeError
:
https://github.com/m0n0l0c0/electron-router/blob/db1f1fa487bc98552eaa47a18e562fd4e92cc365/router.js#L411-L412
A possible solution would be to bind clean to the instance during construction:
}
// Bind clean to instance to make it usable as event handler
this.clean = this.clean.bind(this)
this._setup(true, cfg)
}
If that sounds feasible to you, I can prepare a PR.
I am unable to install. He's sending it to a private directory on his github. The error in the created log record.
.
"install" "electron-router"
28 verbose node v10.15.3
29 verbose npm v6.11.3
30 error code ENOENT
31 error syscall spawn git
32 error path git
33 error errno ENOENT
34 error enoent Error while executing:
34 error enoent undefined ls-remote -h -t https://github.com/m0n0l0c0/eventemitter3.git
34 error enoent
34 error enoent
34 error enoent spawn git ENOENT
35 error enoent This is related to npm not being able to find a file.
36 verbose exit [ 1, true ]
Hello Gentlemen,
we're using electron-router in combination with electron and React.
Received events are used to update some react states and consequently
UI elements.
When leaving React page, a certain method componentWillUnmount() gets called,
where we try to remove listeners in order to avoid React errors about updating unmounted
component.
Although removeListener() is correctly called, the event does not seem to de-register.
Next time when loading the tab, we get double the number of events. PLease look at
attached photo.
Do you have any idea about that?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.